类型类Contravariant
家族代表了 Haskell 生态系统中的标准和基本抽象:
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
但是,要理解这些类型类背后的概念并不容易。我认为如果您能看到一些反例,将有助于更好地理解这些类型类。那么,本着Not a Functor/Functor/Applicative/Monad 的好例子的精神?,我正在寻找满足以下要求的数据类型的对比示例:
- 不是
Contravariant
?的类型构造函数 - 一个类型构造函数,它是 a
Contravariant
,但不是Divisible
? - 一个类型构造函数,它是 a
Divisible
,但不是 aDecidable
? - 类型构造函数是
Decidable
?