[Haskell-cafe] Ocaml for Haskellers tutorial
Henning Thielemann
schlepptop at henning-thielemann.de
Sat Apr 17 18:03:39 EDT 2010
Bas van Dijk schrieb:
>
> I don't know why the heap and stack overflow problems go away. So lets
> look at the core output of the latter program:
>
> $ ghc-core -- -O2 FoldlProfile.hs
>
> $wsum :: [Int] -> Int#
> $wsum = \ (w_s1rS :: [Int]) -> $wfoldl_f 0 w_s1rS
>
> $wfoldl_f :: Int# -> [Int] -> Int#
> $wfoldl_f =
> \ (ww_s1rK :: Int#) (w_s1rM :: [Int]) ->
> case w_s1rM of _ {
> [] -> ww_s1rK;
> : x_aeb xs_aec ->
> case x_aeb of _ { I# y_aUb ->
> $wfoldl_f (+# ww_s1rK y_aUb) xs_aec
> }
> }
>
> Apparently, because of the latter foldl definition, GHC is able to
> optimize the foldl for uboxed ints.
>
> But why doesn't the recursive call:
>
> $wfoldl_f (+# ww_s1rK y_aUb) xs_aec
>
> allocate (+# ww_s1rK y_aUb) on the heap? Are unboxed values always
> evaluated strictly?
>
I think so.
More information about the Haskell-Cafe
mailing list