<br><div class="gmail_quote">On Thu, Mar 17, 2011 at 7:58 PM, Ivan Lazar Miljenovic <span dir="ltr">&lt;<a href="mailto:ivan.miljenovic@gmail.com">ivan.miljenovic@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 18 March 2011 06:25, Bas van Dijk &lt;<a href="mailto:v.dijk.bas@gmail.com">v.dijk.bas@gmail.com</a>&gt; wrote:<br>
&gt; I would like to propose making inits and tails less strict:<br>
&gt;<br>
&gt;  inits                   :: [a] -&gt; [[a]]<br>
&gt; -inits []                =  [[]]<br>
&gt; -inits (x:xs)            =  [[]] ++ map (x:) (inits xs)<br>
&gt; +inits xs                =  [] : case xs of<br>
&gt; +                                  []   -&gt; []<br>
&gt; +                                  x:xs -&gt; map (x:) (inits xs)<br>
&gt;<br>
&gt;  tails                   :: [a] -&gt; [[a]]<br>
&gt; -tails []                =  [[]]<br>
&gt; -tails xxs@(_:xs)        =  xxs : tails xs<br>
&gt; +tails xxs               =  xxs : case xxs of<br>
&gt; +                                   []   -&gt; []<br>
&gt; +                                   _:xs -&gt; tails xs<br>
&gt;<br>
&gt; Having a lazier inits allows the elegant:<br>
&gt; nats = map length (inits nats)<br>
&gt; which loops for the current definition. This definition was due to John Tromp:<br>
&gt; <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>
</div></div>I&#39;m not against this proposal, but am just curious: is there any<br>
reason/need for this lazier definition apart from an elegant (but<br>
possibly not actually needed/useful) trick?</blockquote><div> </div><div>In general with the standard library definitions have been made as lazy as they reasonably can. </div><div><br></div><div>Here, clearly, the initial [] doesn&#39;t depend on the argument being resolved to a cons cell or nil.</div>
<div><br></div><div>For me this is interesting mostly because of the nearly-comonadic </div><div><br></div><div>extend :: ([a] -&gt; b) -&gt; [a] -&gt; [b]</div><div>extend f = map f . tails</div><div><br></div><div>which I would like to be as productive as possible.</div>
<div><br></div><div>-Edward</div></div>