It seems that Haskell has established several naming conventions around monads.
Examples:
T
to the end to obtain the name of the monad transformer (e.g. Reader
-> ReaderT
)runXXX
to perform a monad computation (e.g. runST
, runReader
)liftXXX
for various values of XXX
Are there other naming conventions?
A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.
Monads are simply a way to wrapping things and provide methods to do operations on the wrapped stuff without unwrapping it. For example, you can create a type to wrap another one, in Haskell: data Wrapped a = Wrap a. To wrap stuff we define return :: a -> Wrapped a return x = Wrap x.
So in simple words, a monad is a rule to pass from any type X to another type T(X) , and a rule to pass from two functions f:X->T(Y) and g:Y->T(Z) (that you would like to compose but can't) to a new function h:X->T(Z) .
Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error . The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing . A richer error monad can be built using the Either type.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With