Category:Monads: Difference between revisions
Content deleted Content added
mNo edit summary |
Thundergnat (talk | contribs) m Not a task, its a category. |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1:
In functional programming, the [[wp:Monad_(functional_programming)|Monad]] design pattern is a general solution to the problem of nesting (or 'composing') a class of functions which enclose their output values in some kind of useful wrapping. The output envelope might, for example, contain, in addition to the returned value, a log string, or a boolean indicator of whether or not the input was a legal value. Sometimes the output might simply be enclosed in a list representing a range of possible values rather than a single value.
Functions of this type can not be directly nested with each other, because their output type (wrapped) does not match their input type (raw and unwrapped).
Line 21:
:Nests functions which return their output in an envelope that includes a log string. Nesting ('composing') such functions generates a concatenated log of a chain of function applications.
;the Maybe monad
:Nests partial functions which return their output in a wrapper that includes a boolean flag – indicating whether or not the input value was legal. Composition of these functions avoids the need for exception handling when an illegal value is encountered somewhere along the chain of function applications. The '''invalid''' flag is threaded up through the monad, allowing all further attempts at function application to be bypassed.
;the List monad
:Nests functions which output ranges of possible values, rather than single values. Composing these functions yields cartesian products, and a convenient encoding of set comprehensions.
|