Proposal: making inits and tails less strict
Bas van Dijk
v.dijk.bas at gmail.com
Thu Mar 17 20:25:01 CET 2011
Hello,
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:
http://www.mail-archive.com/haskell@haskell.org/msg21044.html
Discussion deadline: 2 weeks.
Regards,
Bas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: less_strict_inits_and_tails.dpatch
Type: application/octet-stream
Size: 70057 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110317/891c35ac/attachment-0001.obj>
More information about the Libraries
mailing list