Monads
Posted on 2015-08-24 19:16:47 +0900 in Functional Programming
Lecture Contents
Type class really gives one good intuition about Monad
.
Intuitively, it is this ability to use the output from previous computations to decide what computations to run next that makes Monad more powerful than Applicative. The structure of an Applicative computation is fixed, whereas the structure of a Monad computation can change based on intermediate results. This also means that parsers built using an Applicative interface can only parse context-free languages; in order to parse context-sensitive languages a Monad interface is needed
Category theory gives some theorems behind Monad
.
All told, a monad in X is just a monoid in the category of endofunctors of X, with product × replaced by composition of endofunctors and unit set by the identity endofunctor.
Home Work
Exercise 2
Exercise 3
Exercise 4
Test code: