Can someone explain why the one stack overflows and the other one doesn't?

iterateNTimes i f x = foldr (.) id (replicate i f) $ x
tntIO :: IO Int
-- same as replicateM (10^6) $ return 0 , and same as sequence .
replicate (10^6) $ return 0
tntIO = iterateNTimes (10^6) (ap . liftM (:) . return $ ) (return [])
-- produces output
tntMb :: Maybe Int -- overflows
tntMb = iterateNTimes (10^6) (ap . liftM (:) . return $ ) (return [])
-- stack overflow
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to