Re: [Haskell] making inits less strict

7 Apr
2008
7 Apr
'08
4:24 p.m.
john.tromp:
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@haskell.org list, and file a proposal to replace the current definition? http://haskell.org/haskellwiki/Library_submissions We noticed this while implementing lazy bytestrings, which had a similar issue, and fixing it is cheap enough. -- Don
6252
Age (days ago)
6252
Last active (days ago)
0 comments
1 participants
participants (1)
-
Don Stewart