Languages Features Calendar About Lists Add Language
GitHub icon



Monad is a language feature.

In functional programming, a monad is a design pattern that allows structuring programs generically while automating away boilerplate code needed by the program logic. Monads achieve this by providing their own data type, which represents a specific form of computation, along with one procedure to wrap values of any basic type within the monad (yielding a monadic value) and another to compose functions that output monadic values (called monadic functions).This allows monads to simplify a wide range of problems, like handling potential undefined values (with the Maybe monad), or keeping values within a flexible, well-formed list (using the List monad). With a monad, a programmer can turn a complicated sequence of functions into a succinct pipeline that abstracts away auxiliary data management, control flow, or side-effects.Both the concept of a monad and the term originally come from category theory, where it is defined as a functor with additional structure. Read more on Wikipedia...

Languages with Monad include Haskell

Example from Haskell:

-- parseExpr = parseString <|> parseNumber parseString = do char '"' x <- many (noneOf "\"") char '"' return (StringValue x) parseNumber = do num <- many1 digit return (NumberValue (read num))

Article source

PLDB - Build the next great programming language 路 v2022 Docs Acknowledgements Email GitHub