+1<br><br><div class="gmail_quote">On Thu, Mar 17, 2011 at 3:25 PM, Bas van Dijk <span dir="ltr"><<a href="mailto:v.dijk.bas@gmail.com" target="_blank">v.dijk.bas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I would like to propose making inits and tails less strict:<br>
<br>
inits :: [a] -> [[a]]<br>
-inits [] = [[]]<br>
-inits (x:xs) = [[]] ++ map (x:) (inits xs)<br>
+inits xs = [] : case xs of<br>
+ [] -> []<br>
+ x:xs -> map (x:) (inits xs)<br>
<br>
tails :: [a] -> [[a]]<br>
-tails [] = [[]]<br>
-tails xxs@(_:xs) = xxs : tails xs<br>
+tails xxs = xxs : case xxs of<br>
+ [] -> []<br>
+ _:xs -> tails xs<br>
<br>
Having a lazier inits allows the elegant:<br>
nats = map length (inits nats)<br>
which loops for the current definition. This definition was due to John Tromp:<br>
<a href="http://www.mail-archive.com/haskell@haskell.org/msg21044.html" target="_blank">http://www.mail-archive.com/haskell@haskell.org/msg21044.html</a><br>
<br>
Discussion deadline: 2 weeks.<br>
<br>
Regards,<br>
<font color="#888888"><br>
Bas<br>
</font><br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br>