
On 4/9/06, Aaron Denney
inits xs = zipWith take [0..] $ map (const xs) (undefined:xs)
Nicest version so far!
(I still think letting head $ inits undefined be [] rather than undefined is better than the current def.)
Yes, from a termination point of view it surely seems better with the lazy version. But I believe that this is the wrong way of seeing it. These termination issues are hardly any problem in every-day programming. But what few people here seem to realize is that a change in the strictness of a function will change the space behaviour of a program. I use that as a rule of thumb when inspecting Haskell code: whenever the strictness changes that will lead to a change in memory consumption. So changing inits to a lazier version will not affect a lot of program termination-wise but it will have effects on the space consumption. Whether these effects will be good of bad depends on the program, but the fact remains, there will be a change. I think this is unwelcome and that's why I think that the strictness properties of the Prelude functions should be preserved. Cheers, /Josef