[Haskell-cafe] Monad transformers [Stacking monads]
dougal at dougalstanton.net
Tue Oct 7 08:58:54 EDT 2008
On Mon, Oct 6, 2008 at 9:48 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> Andrew Coppin wrote:
>> I have some longwinded code that works, but I'm still thinking about how
>> to do this more elegantly. It looks like what I really need is something
>> type M = StateT State (ResultSetT (ErrorT ErrorType Identity))
>> Is that the correct ordering?
>> If so, I guess that means I have to somehow construct ResultSetT. Is there
>> an easy way to do that, given that I already have ResultSet? For example, if
>> I put ResultSet into Traversable, would that let me do it?
> ...and again I'm talking to myself... :-/
> So after much experimentation, I have managed to piece together the
> following facts:
> - It appears that the outer-most monad transformer represents the inner-most
> monad. So "StateT Foo ListT" means a list of stateful computations, while
> "ListT (StateT Foo)" means a stateful list of computations.
Have you read "Monad Transformers Step by Step"  by Martin
Grabmueller? It's a fantastic introduction to these beasties, leading
the reader through a series of transformations from pure code to using
about 4 different monads/transformers for all sorts of extra features.
Seriously recommend it.
More information about the Haskell-Cafe