7 Apr
2008
7 Apr
'08
7:11 p.m.
The standard definition of inits: inits [] = [[]] inits (x:xs) = [[]] ++ map (x:) (inits xs) is unnecessarily strict, evaluating its argument before yielding the initial [] of the result. An improved version is: inits l = [] : case l of [] -> [] (x:xs) -> map (x:) inits xs This allows one to define for instance nats = map length (inits nats) which loops for the standard definition. regards, -John