refined icon indicating copy to clipboard operation
refined copied to clipboard

Show type class instance for Predicate

Open koshelev opened this issue 10 years ago • 5 comments

Remove Predicate.show and use Show type class instead

koshelev avatar Aug 05 '15 16:08 koshelev

Agreed. The string representation of a predicate should not be the concern of the Predicate type class.

fthomas avatar Aug 05 '15 16:08 fthomas

I'd like to add that we can't use something like cats.Show here because it has only one type parameter (Show[T] { def show(t: T): String }) but what we need is a typeclass that can show a value of type T for some predicate P. So we need at least a Show[T, P] { def show(t: T): String }.

fthomas avatar Oct 13 '15 19:10 fthomas

Is not it T Refined P? Or another class F[T, P] ?

koshelev avatar Oct 13 '15 19:10 koshelev

Currently the F is not needed to show a T in the context of a predicate P. Would the string representation differ for different Fs? For me, the F (which has a RefType instance) is just the carrier for the refinement, it is something that ties the T and P together with the additional meaning that the contained T is valid according to P. We also want to use show for values that are invalid and if we use Show[F[T, P]] we'd have to construct invalid F[T, P] values before we can show them.

fthomas avatar Oct 13 '15 19:10 fthomas

Just a remark: Show would also be beneficial for aliases like type GreaterEqual[N] = Not[Less[N]]. The Validate instance for GreaterEqual[N] gets currently assembled from a Validate for Not and Less with an acceptable validate function and with a show function that produces strings like "!(1 < 0)" (which are technically correct but not very readable). It would be nice to provide a Show[GreaterEqual[N]] explicitly which produces strings like "(1 >= 0)".

fthomas avatar Oct 30 '15 18:10 fthomas