[Haskell-cafe] Merry monad mixup?
pumpkingod at gmail.com
Fri Jan 28 20:46:00 CET 2011
Beware of ListT. It only works if your internal monad is commutative, which
IO is not. (Maybe would work, for example)
On Fri, Jan 28, 2011 at 2:41 PM, Chris Smith <cdsmith at gmail.com> wrote:
> On Fri, 2011-01-28 at 11:20 -0800, michael rice wrote:
> > The first and third work, but not the second. Why?
> When you use a do block, it can be the syntactic sugar for whatever
> monad you like; but you do have to make a choice. Your first example
> had a do block for the IO monad. Your third example used the  monad.
> Both are fine.
> The second, though, wasn't clear on what monad it was using. When you
> used the (<-) syntax to nondeterministically choose from a list, the
> compiler settled upon the  monad. But then the next line was a
> statement in the IO monad. That's inconsistent, hence the error.
> Perhaps you wanted to build a monad out of both behaviors? In this
> case, you should likely look into monad transformers, and in particular,
> the ListT monad transformer in the List package. This would allow you
> to write the code you did in a monad called ListT IO, except that the IO
> actions would need to be lifted through the use of either `lift` or
> Chris Smith
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe