Dynamic types: GHCI works, GHC doesn't?

Andre Pang andrep@cse.unsw.EDU.AU
Sat, 1 Jun 2002 23:23:49 +1000

On Sat, Jun 01, 2002 at 11:01:57PM +1000, Andre Pang wrote:

> It seems that the fromDynamic and fromDyn functions seem to work
> if you load your module into GHCI, but they don't work when you
> compile it into a stand-alone executable with GHC.

.. unless you compile it with -O2:

    23:18(0) .../project/dynamic_types-bug% ghc --make -package lang -O2 DynamicTypesBug.hs 
    ghc-5.02.2: chasing modules from: DynamicTypesBug.hs
    Compiling Main             ( DynamicTypesBug.hs, ./DynamicTypesBug.o )
    ghc: linking ...
    23:18(0) .../project/dynamic_types-bug% ./a.out
    Static type: FootnoteData [Char] Int
    Coerced (dynamic) type: FootnoteData [Char] Int
    Does dynamic type == static type?  True
    Attempting to run fromDynamic on the dynamic type ...
    5. This be the footnote


It also seems to work with -O1.

I should note that I observed the buggy GHC behaviour with
-fvia-c as well, regardless of whether gcc-2.95 or gcc-3.1 was

Putting -O0 on the GHC commandline, or omitting the -O option
altogether, appears to trigger the bug.  This doesn't happen with
GHCI (i.e. 'ghci -O0' seems to work).

#ozone/algorithm <andrep@cse.unsw.EDU.AU>          - b.sc (comp. sci+psych)