[Haskell-cafe] Re: Books for "advanced" Haskell
Stephen Tetley
stephen.tetley at gmail.com
Fri Mar 5 08:59:53 EST 2010
2010/3/5 Günther Schmidt <gue.schmidt at web.de>:
> When you say that you use monads to the left and right, do you mean using
> pre-defined monad instances, or do you construct your own, ie. define
> something to be an instance of a monad and then write codes using that
> instance?
Hi Günther
One view of Monads (in the context of Haskell) is that they provide effects:
- State Monad - state
- Maybe monad - partiality (answer or failure)
- Error monad - partiality with some answer type for the failure
(variation of Maybe)
- Environment monad aka Reader - read only access to "context"
- Writer monad - tracing - write only access to "context"
- List monad - non-determinism
- Resumption monad - interleaving for (simulating) concurrency
Because a monad (in the context of Haskell) is an implementation of
the Monad type class and the obligation to satisfy the monad laws,
there are quite few 'variations on a theme' monads e.g.:
Jerzy Karczmarczuk's time travel State Monad
http://users.info.unicaen.fr/~karczma/arpap/revpearl.pdf
Ralf Hinze's - partial CPS monad "Typed Quote/Antiquote"
-- paper currently off-line unfortunately
The codensity monad - variation on the CPS monad
http://www.cs.nott.ac.uk/~gmh/wrapper2.pdf
Plus unique but currently rare monads, e.g:
Probability
http://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf
These latter monads still represent effects, and one should be able to
define them as transformers (I think, I haven't actually tried), but
they less common presumably because people have found less need for
the effects they provide.
There are also monads where I'd struggle to claim any analogous
'effect' (maybe they have one and I don't understand the presentation,
or maybe they don't actually have one) - generally these monads don't
seem to have escaped from the mathematical world to the Haskell world.
E.g. the monad of locales, power locales
http://www.cs.bham.ac.uk/~mhe/papers/pinjective.pdf
To work with monads in Haskell its not ignoble simple to decide what
effect or combination of effects you want and use the relevant monad
(for a single effect) or build a transformer (for multiple effects).
Best wishes
Stephen
More information about the Haskell-Cafe
mailing list