
11 Apr
2006
11 Apr
'06
6:39 a.m.
Ross Paterson wrote:
On Mon, Apr 10, 2006 at 03:54:09PM +0100, Chris Kuklewicz wrote:
inits' = helper id where helper f [] = (f []):[] helper f (x:xs) = (f []):helper (f.(x:)) xs
inits = map reverse . scanl (flip (:)) []
It's not really surprising: the nested composition built by helper is essentially a list, which is traversed by ($ []). If scanl were defined using build it might run a tiny bit faster.
an alternative helper (are expanding scanl) would be: inits = helper [] where helper l xs = reverse l : case xs of [] -> [] x : r -> helper (x : l) r C.