gpt4 book ai didi

haskell - Haskell 的 <- 的 clojure 等价物是什么?

转载 作者:行者123 更新时间:2023-12-01 07:39:08 25 4
gpt4 key购买 nike

我试图找出 IO monad 和 <-我经常在 Haskell 代码中看到的语法。我已经看到它与多种数据类型一起使用,包括数组和 IO。

如果我自己指定一个,clojure 中的等效操作是什么?

最佳答案

Do-notation 只是标准 monad 操作的糖。例如,如果你有这样的事情:

do
x <- someMonad
return (someFunction x)

这相当于:
someMonad >>= \x -> return (someFunction x)

因此,使用众多 monad 库之一的等效 Clojure 可能是这样的:
(m-bind some-monad (fn [x] (m-result (some-function x))))

关于haskell - Haskell 的 <- 的 clojure 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20431964/

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