monad的所有命名约定是什么? [英] What are all of the monad naming conventions?
问题描述
Haskell似乎已经围绕monad建立了一些命名约定.
It seems that Haskell has established several naming conventions around monads.
示例:
- 在末尾附加
T
以获取monad转换器的名称(例如Reader
->ReaderT
) - 使用
runXXX
进行monad计算(例如runST
,runReader
) -
liftXXX
用于XXX
的各种值
- appending
T
to the end to obtain the name of the monad transformer (e.g.Reader
->ReaderT
) - using
runXXX
to perform a monad computation (e.g.runST
,runReader
) liftXXX
for various values ofXXX
还有其他命名约定吗?
推荐答案
-
runX m
,其中m :: X a
将运行X
monad,并返回副作用"以及monad结果a
.runX m
wherem :: X a
will run theX
monad and return the "side effect" along with the monad result,a
.evalX m
将运行计算并返回结果a
.evalX m
will run the computation and return the result,a
.execX m
将运行计算并返回副作用",但不返回结果.execX m
will run the computation and return the "side effect" but not the result.这些升降机具有多种风格,对于我来说想在SO答案中解释它们可能有些棘手.您可能应该知道
lift
和liftIO
,并了解/最终找到其他变体,例如liftWith
和liftBaseWith
.例如,请参见EZYang关于该主题的帖子.The lifts come in various flavors that can be a bit too tricky for me to want to explain them in a SO answer. You should probably know
lift
andliftIO
and be aware of / eventually seek out the other variants such asliftWith
andliftBaseWith
. See, for example, EZYang's posting on the topic.在monad名称后附加
T
表示转换器.在函数名称后添加M
表示它为单子.附加_
表示结果将被忽略.appending a
T
after the monad name implies transformer. Appending anM
after a function name implies it is monadic. Appending an_
implies the result is ignored.所有其他带后缀的字母均表示用钩".
All other suffixed letters mean "use hoogle".
这篇关于monad的所有命名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!