The Contravariant family of typeclasses represents standard and fundamental abstractions in the Haskell ecosystem:
class Contravariant f where
contramap :: (a -> b) -> f b -> f a
class Contravariant f => Divisible f where
conquer :: f a
divide :: (a -> (b, c)) -> f b -> f c -> f a
class Divisible f => Decidable f where
lose :: (a -> Void) -> f a
choose :: (a -> Either b c) -> f b -> f c -> f a
However, it's not that easy to understand the concepts behind these typeclasses. I think it would help to understand these typeclasses better if you could see some counterexamples for them. So, in the spirit of Good examples of Not a Functor/Functor/Applicative/Monad?, I'm looking for contrasting examples of data types which satisfy the following requirements:
- A type constructor which is not a
Contravariant? - A type constructor which is a
Contravariant, but notDivisible? - A type constructor which is a
Divisible, but is not aDecidable? - A type constructor which is a
Decidable?
(partial answer)
Not contravariant
is not contravariant (it is, however, a covariant functor).
Contravariant, but not divisible
is contravariant but it can not be
Divisiblesince otherwiseA note on "divisible but non decidable"
I don't have a reasonable example for a divisible which is not decidable. We can observe that such a counterexample must be such because it violates the laws, and not just the type signature. Indeed, if
Divisible Fholds,satisfies the type signatures of the methods.
In libraries we find
Const mas a divisible, whenmis a monoid.Perhaps this can not be a lawful
Decidable? (I'm unsure, it seems to satisfy theDecidablelaws, but there's noDecidable (Const m)instance in the libraries.)Decidable
Taken from the libraries: