You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The relevant type for Show is certainly a good Contravariant, Divisible, and Decidable:
newtypeShowsPreca=ShowsPrec{runShowsPrec::Int->a->ShowS}instanceContravariantShowsPrecwhere
contramap f (ShowsPrec s) =ShowsPrec$\p -> s p . f
instanceDivisibleShowsPrecwhere
conquer =ShowsPrec$\_ _ ->id
divide f (ShowsPrec sb) (ShowsPrec sc) =ShowsPrec$\p ->uncurry (\b c -> sb p b . sc p c) . f
instanceDecidableShowsPrecwhere
lose f =ShowsPrec$\_ -> absurd . f
choose f (ShowsPrec sb) (ShowsPrec sb) =ShowsPrec$\p ->either (sb p) (sc p) . f
It also admits a number of useful combinators:
showCharP::Char->ShowsPreca
showCharP c =ShowsPrec$\_ _ ->showChar c
showStringP::String->ShowsPreca
showStringP str =ShowsPrec$\_ _ ->showString str
(>*):: (Divisiblef) =>f()->fa->fa(>*)= divide ((,) ())
(*<):: (Divisiblef) =>fa->f()->fa(*<)= divide (\a -> (a, ()))
parenP::Int->ShowsPreca->ShowsPreca
parenP p0 (ShowsPrec sh) =ShowsPrec$\p a ->showParen (p > p0) $ sh (p0 +1) a
These are just examples, but it'd allow building up a ShowsPrec from smaller pieces, and fit with Equivalence and Comparison as "Contravariants arising from Prelude typeclasses".
The text was updated successfully, but these errors were encountered:
The relevant type for Show is certainly a good Contravariant, Divisible, and Decidable:
It also admits a number of useful combinators:
These are just examples, but it'd allow building up a ShowsPrec from smaller pieces, and fit with Equivalence and Comparison as "Contravariants arising from Prelude typeclasses".
The text was updated successfully, but these errors were encountered: