简体   繁体   English

列出单子和单子吗?

[英]Is list a monad and comonad?

The list monad is given here . 单子列表在这里给出 Also see Spivak's paper here . 另请参见Spivak的论文 So list is a monad. 所以清单是单子。 Is it a comonad? 是一个笨蛋吗? How would you prove that? 您将如何证明?

The list type constructor a ↦ μ L. 1 + a * L doesn't admit a comonad structure. 列表类型构造函数a↦μL。1 a ↦ μ L. 1 + a * L不允许comonad结构。 Recall that if it were a comonad, we'd have (using the names from Haskell's Functor and Comonad typeclasses) 回想一下,如果它是一个普通符号,我们将拥有(使用Haskell的FunctorComonad类型类的名称)

fmap :: ∀  a b. (a → b) → [a] → [b]
extract :: ∀  a. [a] → a
duplicate :: ∀  a. [a] → [[a]]

However, even without going into any required laws, extract cannot be implemented, since its input could be the empty list, giving no way to come up with an a . 但是,即使不遵循任何必需的法律, extract也无法实现,因为extract的输入可能是空列表,无法给出a

The nonempty list type constructor a ↦ μ NE. a + a * NE 非空列表类型构造函数a ↦ μ NE. a + a * NE a ↦ μ NE. a + a * NE does admit a comonad structure, with extract returning the first element, and duplicate mapping [x, y, ..., z] to [[x], [x, y], ..., [x, y, ..., z]] (note that each of them are non-empty by construction). a ↦ μ NE. a + a * NE确实接受了共纳结构,其中extract返回第一个元素,并将[x, y, ..., z] duplicate[[x], [x, y], ..., [x, y, ..., z]] (请注意,它们在构造上都是非空的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM