[Haskell] making inits less strict
dons at galois.com
Mon Apr 7 16:24:54 EDT 2008
> The standard definition of inits:
> inits  = []
> inits (x:xs) = [] ++ map (x:) (inits xs)
> is unnecessarily strict, evaluating its argument
> before yielding the initial  of the result.
> An improved version is:
> inits l =  : case l of  -> 
> (x:xs) -> map (x:) inits xs
> This allows one to define for instance
> nats = map length (inits nats)
> which loops for the standard definition.
Can you forward this to the libraries at haskell.org list,
and file a proposal to replace the current definition?
We noticed this while implementing lazy bytestrings, which had
a similar issue, and fixing it is cheap enough.
More information about the Libraries