Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are all of the monad naming conventions?

Tags:

haskell

monads

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?

like image 236
ErikR Avatar asked Feb 27 '12 00:02

ErikR


People also ask

What are 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.

What is a monad example?

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.

What is a monadic type?

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

Is maybe a monad?

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.


1 Answers

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

like image 137
Thomas M. DuBuisson Avatar answered Oct 12 '22 12:10

Thomas M. DuBuisson