
On 2006-04-08, Tim Toorop
Josef Svenningsson wrote:
On 4/8/06, Tim Toorop
wrote: On the other hand, I think the new spiffy inits is quite clear once you notice why its map (const xn) $ undefined:xn
I think it would be even clearer if it were defined like this:
inits xs = zipWith take [0..] $ map (const xs) xs
That way you don't have this ugly special case for the first element in the list. But there is an even better advantage: it is strict again! So it's termination properties are exactly like the Prelude one. This version *can* be used as a drop-in replacement of the Prelude version.
Cheers,
/Josef
Yes it is very clear ... except for the fact that it doesn't work correctly. It misses the last element. now we could write inits2' xn = (zipWith take [0..] $ map (const xn) xn ) ++ [xn] Though I dont know if this really is clearer, and it seems to make the garbage collector work slightly more And which I think does exactly the same as inits' xn@(_:_) = zipWith take [0..] $ map (const xn) $ undefined:xn
Yes, but is there any real need to use the ugly pattern syntax? Surely inits xs = zipWith take [0..] $ map (const xs) (undefined:xs) (I still think letting head $ inits undefined be [] rather than undefined is better than the current def.) -- Aaron Denney -><-