Proposal: making inits and tails less strict
I would like to propose making inits
and tails
less strict:
inits :: [a] -> [[a]]
-inits [] = [[]]
-inits (x:xs) = [[]] ++ map (x:) (inits xs)
+inits xs = [] : case xs of
+ [] -> []
+ x:xs -> map (x:) (inits xs)
tails :: [a] -> [[a]]
-tails [] = [[]]
-tails xxs@(_:xs) = xxs : tails xs
+tails xxs = xxs : case xxs of
+ [] -> []
+ _:xs -> tails xs
Having a lazier inits
allows the elegant:
nats = map length (inits nats)
which loops for the current definition. This definition was due to John Tromp
In the thread on the libraries list there were some +1's and no objections.
Trac metadata
Trac field | Value |
---|---|
Version | 7.0.3 |
Type | Task |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |