gpt4 book ai didi

haskell - underscore.js 中的 chain 函数是否创建了一个 monad?

转载 作者:行者123 更新时间:2023-12-02 23:07:33 24 4
gpt4 key购买 nike

the chain documentation你发现:

Calling chain on a wrapped object will cause all future method calls to return wrapped objects as well. When you've finished the computation, use value to retrieve the final value.

chain 也是如此函数创建一个 monad?

最佳答案

不,不是单子(monad),而是共单子(monad)!它将一个接受包装对象并返回普通值的函数转换为一个既接受又返回包装对象的函数。作为 Haskell 类型签名,将是:

(Wrapped a -> b) -> (Wrapped a -> Wrapped b)

value 的类型签名是:

Wrapped a -> a

这些正是 comonad 所需要的。第一个函数通常称为 extend,第二个函数称为 extract

您可以将 comonad 视为带有一些额外上下文的值。这当然正是 chain 的作用。

参见this Stackoverflow question有关 comonad 的更多信息。

关于haskell - underscore.js 中的 chain 函数是否创建了一个 monad?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com