roam/20220310115927-monad.org

1.2 KiB

Monad

A monad is just a monoid in the category of endofunctors.

In Software Development, this refers to an Applicative Functor that provides a method for applyling a function taking a bare value and returning a wrapped value to a value already wrapped in that same type.

In Haskell, the function to do this is called bind, and is available as the infix operator >>=. This method is useful for sequentially applying functions which generate values wrapped in a Monad, abstracting away logic between each sequential application. This behavior leads some people to refer to Monads as "programmable semicolons", referring to imperative, C-like languages in which each line of code is terminated with a semicolon and executed in sequence. Haskell's "do notation" provides syntactic sugar for codifying such sequences.

  (>>=) :: Monad m => m a -> (a -> m b) -> m b
Bind function in Haskell