[Haskell-cafe] Haskell maximum stack depth

Adrian Hey ahey at iee.org
Thu Feb 7 12:53:30 EST 2008


Adrian Hey wrote:
> AFAICT neilGobbler isn't even entirely safe as an implementation of
> an eager take. There's nothing the Haskell standard to stop it being
> transformed into..
> 
> neilGobbler :: Int -> [x] -> [x]
> neilGobbler n xs = length (take n xs) `seq` take n xs

Whoops, I see stackGobbler has the same problem..
-- Strict version of take
stackGobbler :: Int -> [x] -> [x]
stackGobbler 0 _      = []
stackGobbler _ []     = []
stackGobbler n (x:xs) = let xs' = stackGobbler (n-1) xs
                         in  xs' `seq` (x:xs')

I guess this is an example of the Haskell standard needing to be
tightened up a bit, but that is another story..

Regards
--
Adrian Hey


More information about the Haskell-Cafe mailing list