Category:Monads: Difference between revisions

Content added Content deleted
No edit summary
mNo edit summary
Line 4: Line 4:
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).
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).


The monad pattern consists of writing two higher-order functions which solve this problem, allowing the programmer to easily nest the application of such functions, by abstracting out the mechanics, and making sure that a function does not choke on an unexpected input type (a wrapped type, when it was expected a raw type).
The monad pattern consists of writing two higher-order functions which solve this problem, allowing the programmer to easily nest the application of such functions, by abstracting out the mechanics, and making sure that a function does not choke on an unexpected input type (a wrapped type, when it was expecting a raw type).


More specifically, the two higher-order functions of the monad pattern handle the details of: 1. wrapping data in a particular kind of envelope, and 2. Providing other functions with direct access to the contents of an enclosing envelope.
More specifically, the two higher-order functions of the monad pattern handle the details of: 1. wrapping data in a particular kind of envelope, and 2. Providing other functions with direct access to the contents of an enclosing envelope.