[Haskell-cafe] Re: Optimizing 'sequence'

Gracjan Polak gracjanpolak at gmail.com
Wed Jul 23 05:20:39 EDT 2008


Chaddaï Fouché <chaddai.fouche <at> gmail.com> writes:
> 2008/7/22 Luke Palmer <lrpalmer <at> gmail.com>:
> > A little formal reasoning reveals that sequence1 = sequence2 exactly
> > when (>>=) is strict in its left argument.  There are four common
> > monads which are _not_: Identity, Reader, Writer, State (and RWS by
> > extension).
> 
> Still if that makes that much of a difference, maybe we could envision
> putting a sequence' in the library ?
> 

Yes, in my experiments this is to be or not to be. Stack space is limited. 
Also processing time goes down by 800%, so it is a big deal sometimes.

Incomplete list of functions affected:

sequence
mapM
foldM
Text.ParserCombinators.Parsec.Combinator(many1,sepBy,endBy,manyTill)
Text.ParserCombinators.ReadP(many,many1,count,sepBy,endBy,manyTill)
...

As far as I know sequence could be specialized to IO monad and use my
transformation.

How do I reason if >>= for parsers is lazy in its first argument?

-- 
Gracjan




More information about the Haskell-Cafe mailing list