Understanding strictness of ghc output
Simon Peyton-Jones
simonpj at microsoft.com
Tue Jun 22 09:28:21 EDT 2004
| That contradicts my intution for seq. I would read it as "h is forced
| before h is forced", and I would think that (h `seq` h) is equivalent
| to h.
|
| Were I am wrong?
You're not wrong -- Malcolm is. The function is certainly strict in h,
and GHC finds it.
Here's what I get when I compile your program (with a suitable
definition of AVL). The function $wpoly_addHeight is the worker for
addHeight. GHC has worked out that addHeight is strict, and has unboxed
the first argument, so that it is now of type Int#, as you can see.
The DmdType for the Int# is indeed "L" but that's irrelevant because
Int# values are always evaluated. The demand info is always L for an
unboxed type.
Simon
Rec {
Foo.$wpoly_addHeight :: forall e.
GHC.Prim.Int# -> Foo.AVL e -> GHC.Prim.Int#
[GlobalId]
Arity 2 NoCafRefs Str: DmdType LS
Foo.$wpoly_addHeight = \ @ e ww :: GHC.Prim.Int# w :: Foo.AVL e ->
case w of wild {
Foo.P ds ds1 r -> Foo.$wpoly_addHeight @ e
(GHC.Prim.+# ww 2) r;
Foo.Z l ds ds1 -> Foo.$wpoly_addHeight @ e
(GHC.Prim.+# ww 1) l;
Foo.N l ds ds1 -> Foo.$wpoly_addHeight @ e
(GHC.Prim.+# ww 2) l;
Foo.E -> ww
}
end Rec }
Foo.height :: forall e. Foo.AVL e -> GHC.Base.Int
[GlobalId]
Arity 1 NoCafRefs Str: DmdType Sm
Foo.height = \ @ e w :: Foo.AVL e ->
case Foo.$wpoly_addHeight @ e 0 w of ww { __DEFAULT ->
GHC.Base.I# ww
}
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org
[mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Tomasz Zielonka
| Sent: 22 June 2004 14:18
| To: Malcolm Wallace
| Cc: glasgow-haskell-users at haskell.org
| Subject: Re: Understanding strictness of ghc output
|
| On Tue, Jun 22, 2004 at 01:52:44PM +0100, Malcolm Wallace wrote:
| >
| > Same again. Try
| > addHeight h E = h `seq` h
| >
| > which, although it looks bizarre, actually forces the evaluation of
h,
| > whilst simply returning it does not.
|
| That contradicts my intution for seq. I would read it as "h is forced
| before h is forced", and I would think that (h `seq` h) is equivalent
| to h.
|
| Were I am wrong?
|
| Best regards,
| Tom
|
| --
| .signature: Too many levels of symbolic links
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list