monad的所有命名约定是什么? [英] What are all of the monad naming conventions?

查看:100
本文介绍了monad的所有命名约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Haskell似乎已经围绕monad建立了一些命名约定.

It seems that Haskell has established several naming conventions around monads.

示例:

  • 在末尾附加T以获取monad转换器的名称(例如Reader-> ReaderT)
  • 使用runXXX进行monad计算(例如runSTrunReader)
  • 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 of XXX

还有其他命名约定吗?

推荐答案

  • runX m,其中m :: X a将运行X monad,并返回副作用"以及monad结果a.

    • runX m where m :: X a will run the X 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答案中解释它们可能有些棘手.您可能应该知道liftliftIO,并了解/最终找到其他变体,例如liftWithliftBaseWith.例如,请参见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 and liftIO and be aware of / eventually seek out the other variants such as liftWith and liftBaseWith. See, for example, EZYang's posting on the topic.

      在monad名称后附加T表示转换器.在函数名称后添加M表示它为单子.附加_表示结果将被忽略.

      appending a T after the monad name implies transformer. Appending an M after a function name implies it is monadic. Appending an _ implies the result is ignored.

      所有其他带后缀的字母均表示用钩".

      All other suffixed letters mean "use hoogle".

      这篇关于monad的所有命名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆