[Haskell-beginners] Using a monadic operation in a list comprehension.

Derek McLoughlin derek.mcloughlin at gmail.com
Sun Sep 21 14:02:55 UTC 2014


Hi,

I'm trying to get Graham Hutton's "Programming with Effects" article
(http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead
of the Tree he provides.

My code is here:

https://gist.github.com/derekmcloughlin/95ab690e0c07c5a7221e

The compiler is complaining about the use of

   lab <- mlabel c

in the list comprehension:

Couldn't match expected type ‘[Tree (a, Int)]’
                with actual type ‘ST (Tree (a, Int))’

This makes sense, but is there any way to execute the monad operation
"mlabel" within the list comprehension? I've tried the
MonadComprehensions extension but still get an error.

Derek.


More information about the Beginners mailing list