

Link: http://codepad.org/6foJr6jI raw code | output | fork ]



Haskell , pasted on Apr 5:

1 2 3 4 5 6 7 8 9 10 11 lfoldl f z [] = z lfoldl f z xs = f ( lfoldl f z ( init xs )) ( last xs ) lreverse = lfoldl ( flip ( : )) [] main = do print $ lfoldl ( + ) 0 [ 1 .. 5 ] print $ lfoldl ( const . const $ 0 ) undefined [ 0 .. ] print $ length $ take 10 $ lreverse [ 0 .. ] -- works! print $ length $ take 10 $ reverse [ 0 .. ] -- kaboom!



Output: 1 2 3 4 5 6 15 0 10 runhugs: Error occurred ERROR - Garbage collection fails to reclaim sufficient space