[Haskell-cafe] Monad transformer to consume a list

Stephan Friedrichs deduktionstheorem at web.de
Tue Apr 7 05:05:39 EDT 2009


Henning Thielemann wrote:

>> 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
> 

But a StateT provides the power to modify the list in other ways than
reading the first element (modify (x:)). Maybe ParsecT is closer to what
I'm looking for ;)

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr


More information about the Haskell-Cafe mailing list