GHC mutual recursion weirdness

Samuel Bronson naesten at gmail.com
Tue May 10 23:29:36 EDT 2005


Someone in #Haskell mentioned a problem they were having with GHC 6.4 and
mutually recursive modules. I'd never tried them, so I tried the simplest
thing I could think of and tried doing it a few ways, and these are my
findings.

I've attached all the relevant files and a tarball for maximum convenience.

I wrote a really, really stupid pair of mutually recursive even and
odd functions and stuck them in modules named Even and Odd. To break
the cycle, I wrote a .hs-boot file for the Even module which gave a
type signature for the even function.

First, I tried it with GHCi. Even worked fine:

Prelude> :l Even
Compiling Even[boot]       ( Even.hs-boot, Even.o-boot )
Compiling Odd              ( ./Odd.hs, interpreted )
Compiling Even             ( Even.hs, interpreted )
Ok, modules loaded: Even, Odd, Even.
*Even> even 1
False

Odd, however, did not:

*Even> :l Odd
Compiling Even[boot]       ( Even.hs-boot, Even.o-boot )
Compiling Odd              ( Odd.hs, interpreted )
Ok, modules loaded: Odd, Even.
*Odd> odd 1
*** Exception: expectJust upsweep_mod:old_linkable

If I were less suspicious (and didn't know for a fact that odd
actually used code from even), I might have thought everything was
fine, until I tried to run it. But then I get this weird error.

ghc --make has similar behaviour, which is not terribly interesting
because it doesn't link unless you run it on a Main module, so I made
two Main modules, EvenMain and OddMain...

ghc --make EvenMain works fine, but ghc --make OddMain does not (even
without deleting the .o/.hi files between):

% ghc --make OddMain.hs 
Chasing modules from: OddMain.hs
Compiling Even[boot]       ( ./Even.hs-boot, ./Even.o-boot )
Skipping  Odd              ( ./Odd.hs, ./Odd.o )
Compiling Main             ( OddMain.hs, OddMain.o )
Linking ...
ghc-6.4: panic! (the `impossible' happened, GHC version 6.4):
        expectJust upsweep_mod:old_linkable

Please report it as a compiler bug to glasgow-haskell-bugs at haskell.org,
or http://sourceforge.net/projects/ghc/.

Hmm, and to think I almost sent this to haskell at haskell.org. Anyway,
there you have it.

-- Sam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Even.hs
Type: text/x-haskell
Size: 127 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/Even.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Even.hs-boot
Type: application/octet-stream
Size: 52 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/Even.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Odd.hs
Type: text/x-haskell
Size: 116 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/Odd.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EvenMain.hs
Type: text/x-haskell
Size: 85 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/EvenMain.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OddMain.hs
Type: text/x-haskell
Size: 82 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/OddMain.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mutual-recursion-weirdness.tar.gz
Type: application/x-gzip
Size: 469 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20050510/24cc7580/mutual-recursion-weirdness.tar.bin


More information about the Glasgow-haskell-bugs mailing list