【发布时间】:2019-10-01 10:21:31
【问题描述】:
The Contravariant family of typeclasses 代表 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
但是,要理解这些类型类背后的概念并不容易。我认为如果您能看到一些反例,将有助于更好地理解这些类型类。因此,本着Good examples of Not a Functor/Functor/Applicative/Monad? 的精神,我正在寻找满足以下要求的数据类型对比示例:
- 不是
Contravariant的类型构造函数? - 类型构造函数是
Contravariant,但不是Divisible? - 类型构造函数是
Divisible,但不是Decidable? - 类型构造函数是
Decidable?
【问题讨论】:
-
请注意,大多数(即所有“非平凡”)函子不是逆变的。
-
@AJFarmar 是的,想出一个不是
Contravariant的数据类型的例子并不难,但这也不是问题中最有趣的部分:) -
潜在的接近选民:这个问题不应该被关闭,原因讨论in my Meta answer。
-
@Shersh “但我认为这个问题不应该结束”——我也不认为。我相信,这些投票主要是 SO 审查系统的人工制品,有时会欺骗人们对他们可能不应该做出判断的问题形成强烈的意见。
标签: haskell typeclass functor contravariant