[Haskell-cafe] Monad transformer to consume a list

Tom Schrijvers Tom.Schrijvers at cs.kuleuven.be
Tue Apr 7 06:01:47 EDT 2009

>> Hello,
>> is there a monad transformer to consume an input list? I've got external
>> events "streaming into the monad" that are consumed on demand and I'm
>> not sure if there's something better than a StateT.
> I wondered that, too. I wondered whether there is something inverse to 
> Writer, and Reader is appearently not the answer. Now I think, that State is 
> indeed the way to go to consume a list. Even better is StateT List Maybe:
> next :: StateT [a] Maybe a
> next = StateT Data.List.HT.viewL   -- see utility-ht package

Or make the transformer a MonadPlus transformer and call mzero for the 
empty list?


Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee

tel: +32 16 327544
e-mail: tom.schrijvers at cs.kuleuven.be
url: http://www.cs.kuleuven.be/~toms/

More information about the Haskell-Cafe mailing list