Question regarding the ListT Monad Transformer

Hey all, I'm trying to get my head around the ListT Monad Transformer, and am having trouble working out how to use it. Essentially, I am trying to transform a type of [IO a] to IO [a] I'd assumed that this might work something like this Transform [IO a] to ListT IO a call runListT to transform ListT IO a to IO [a] ..having I'd assumed that this was the correct situation to use a Monad Transformer, as I'm layering monads around each other. However, while the second half of the transformation above is catered for via runListT - I can't seem to work out how to do the first - namely, to write a function of type [IO a] -> ListT IO a . To be honest, I'm not entirely sure I've entirely got my head around Monad Transformers yet - does what I'm describing make any sense at all, and if so, is there any chance you could point me in the right direction towards implementing (and hopefully understanding) this? Cheers, Tim

Excerpts from Tim Cowlishaw's message of Wed Aug 04 13:29:24 -0400 2010:
However, while the second half of the transformation above is catered for via runListT - I can't seem to work out how to do the first - namely, to write a function of type [IO a] -> ListT IO a . To be honest, I'm not entirely sure I've entirely got my head around Monad Transformers yet - does what I'm describing make any sense at all, and if so, is there any chance you could point me in the right direction towards implementing (and hopefully understanding) this?
ListT IO a = IO [a], so you're looking for a function [IO a] -> IO [a]. This function is called sequence :: Monad m => [m a] -> m [a] My best advice for you is to get rid of the newtype wrapping and unwrapping when you're trying to an understand a monad transformer. Cheers, Edward

On 04/08/10 18:42, Edward Z. Yang wrote:
ListT IO a = IO [a], so you're looking for a function [IO a] -> IO [a]. This function is called sequence :: Monad m => [m a] -> m [a]
Aha, yep, that's exactly what I was after! Thanks very much...
My best advice for you is to get rid of the newtype wrapping and unwrapping when you're trying to an understand a monad transformer.
Aah I see - that makes sense, Will try and have another crack at them shortly. Cheers, Tim
participants (2)
-
Edward Z. Yang
-
Tim Cowlishaw