nLab
monads in Haskell

Definition

A monad in Haskell is defined to be a type class with two methods:

classMonadmwhere

>>=::ma(amb)mb

return::ama

such that

x>>=ffx

a>>=returna

(a>>=f)>>=ga>>=(λxfx>>=g)

Remark

m being a monad (m:aa,μ:m 2m,ϵ:id am) on some object a in a 2-category can be expressed in Haskell by

classMonadmwhere

map::(ab)mamb

return::ama

join::m(ma)ma

We have the following translation of Haskell and category theoretical language?:

join:=μ

return:=ϵ

Then from the category theoretical properties of (m,μ,ϵ) we obtain (mixing the two languages)

mapgϵϵg

mapμμmap(mapg)

μmapμμμ

μϵμmapϵ=id

And with the following definitions

mapf:=(λa>>=(returnf))

joina=a>>id

or alternatively

a>>=f:=join(mapfa)

one can verify that the two given definitions of a monad are equivalent.

References

category theory/monads, haskellwiki, wiki

Created on June 16, 2012 21:48:48 by Stephan Alexander Spahn (92.105.169.45)