Yesterday I spent some time reading about Haskell implementations of Monads because I want to prepare some exercise. I share some links and snippets.
- http://www.haskell.org/tutorial/monads.html
- http://www.haskell.org/haskellwiki/Monad
- Laws & syntax
- Monads in other languages
- The essence of functional programming
- This paper explores the use monads to structure functional programs. No prior knowledge of monads or category theory is required.
- Monads increase the ease with which programs may be modified. They can mimic the effect of impure features such as exceptions, state, and continuations; and also provide effects not easily achieved with such features. The types of a program reflect which effects occur.
- The first section is an extended example of the use of monads. A simple interpreter is modified to support various extra features: error messages, state, output, and non-deterministic choice. The second section describes the relation between monads and continuation-passing style. The third section sketches how monads are used in a compiler for Haskell that is written in Haskell.
- Monads for functional programming
- The use of monads to structure functional programs is described. Monads provide a convenient framework for simulating effects found in other languages, such as global state, exception handling, output, or non-determinism. Three case studies are looked at in detail: how monads ease the modification of a simple evaluator; how monads act as the basis of a datatype of arrays subject to in-place update; and how monads can be used to build parsers.
- So far we've seen the monad concept applied to implicitly passing state. However monads can be used to implement several other programming features including: consuming input, producing output, exceptions and exception handling, nondeterminisim. To handle this variety, the basic operations of >>= and return are overloaded functions.
- Monads and Software Engineering
- The key to engineering a large software project is to make changes easy..
- Monads can be used to make functional programs far more adaptable. You need to insert another processing step? Go right ahead, don't worry about plumbing the state. You need another variable in the state? No problem, just change the underlying state and the basic members of the monad. You need to output messages from your computation? No problem, just change the monad to add an output string. You need to handle exceptions or nondeterminism? No problem, just change the monad.
- It might be said that Haskell with monads does not give you much that you won't find in an imperative, nondeterministic language, with extensible, strong, but generic typing, and a powerful applicative expression sublanguage. The problem is there is no such language in common use. Monads make up for many of the drawbacks of Haskell relative to imperative languages, but without giving up any of its strengths.
- Simple example for generation random numbers with a seed.
- `monad-based' approach to the definition of all-solution predicates in lambdaProlog. As a follow-up, we obtain a clarification of Prolog's high-order operators and their similarities and differences with monad comprehensions in functional languages.