Jump to content

Monads/List monad: Difference between revisions

Added an informal description of the monad triple of (T, eta, mu), with notes on the particular case of List.
(Add Factor)
(Added an informal description of the monad triple of (T, eta, mu), with notes on the particular case of List.)
Line 1:
{{draft task}}
[[Category:Monads]]
 
A [[wp:Monad_(functional_programming)|Monad]] is a combination of a data-type with two helper functions written for that type.
 
The data-type can be of any kind which can contain values of some other type – common examples are lists, records, sum-types, even functions or IO streams. The two special functions, mathematically known as '''eta''' and '''mu''', but usually given more expressive names like 'pure' or 'return', and 'bind', abstract away some boilerplate needed for pipe-lining or enchaining sequences of computations on values held in the containing data-type.
 
The bind operator in the List monad enchains computations which return their values wrapped in lists. One application of this is the representation of indeterminacy, with returned lists representing a set of possible values. An empty list can be returned to express incomputability, or computational failure.
 
A sequence of two list monad computations (enchained with the use of bind) can be understood as the computation of a cartesian product.
 
The natural implementation of bind for the List monad is a composition of '''concat''' and '''map''', which, used with a function which returns its value as a (possibly empty) list, provides for filtering in addition to transformation or mapping.
 
 
Demonstrate in your programming language the following:
 
#Construct a List Monad by writing the 'bind' function and the 'unitpure' (sometimes known as 'return') function for that Monad (or just use what the language already has implemented)
#Make two functions, each which take a number and return a monadic number, e.g. Int -> List Int and Int -> List String
#Compose the two functions with bind
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.