What are all of the monad naming conventions?

断了今生、忘了曾经 提交于 2019-12-21 07:12:40

问题


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

Examples:

  • 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

Are there other naming conventions?


回答1:


  • runX m where m :: X a will run the X monad and return the "side effect" along with the monad result, a.

  • evalX m will run the computation and return the result, a.

  • execX m will run the computation and return the "side effect" but not the result.

  • 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.

  • 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".



来源:https://stackoverflow.com/questions/9458700/what-are-all-of-the-monad-naming-conventions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!