问题
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 ofXXX
Are there other naming conventions?
回答1:
runX m
wherem :: X a
will run theX
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
andliftIO
and be aware of / eventually seek out the other variants such asliftWith
andliftBaseWith
. See, for example, EZYang's posting on the topic.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".
来源:https://stackoverflow.com/questions/9458700/what-are-all-of-the-monad-naming-conventions