[Haskell-cafe] Re: Generating a random list
apfelmus
apfelmus at quantentunnel.de
Sat Mar 1 11:45:43 EST 2008
Milos Hasan wrote:
> import System.Random
> import Data.List
>
> randFloats :: [Float]
> randFloats = randoms (mkStdGen 0)
>
> main = print $ sum $ sort $ take 1000000 randFloats
>
> Could it be that Data.List.sort is the culprit that uses O(n) stack
> space here? If so, is this avoidable?
sum is not tail-recursive. Sometimes, GHCs strictness analyzer is able
to optimize that away.
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list