[nhc-bugs] nhc98 module bug

Manuel M. T. Chakravarty chak@cse.unsw.edu.au
Wed, 26 Sep 2001 18:43:51 +1000


The following combination of three modules breaks nhc98
v1.08:

===== First module ======
module M (T, foo)
where

newtype T = T Int

foo   :: Int -> T
foo x  = T (x + 1)

===== Second module ======
module N (foo)
where

import M (T)
import qualified M (foo)

data S = S T

foo   :: Int -> S
foo y  = S $ M.foo y

===== Third module ======
import N (foo)

main = print $ const 42 (foo 100)
=========================

Compile with

  nhc98 -c M.hs
  nhc98 -c N.hs
  nhc98 -c Main.hs

to get

	  Error when renaming::
  Identifier foo defined 2 times.

The problem is quite subtle.  It is the combination of
qualified import of `M.foo' in `N' and export of another
`foo' in `N', where `N.foo' has a type that depends on
`M.T'.  Looking into `N.hi' there are indeed two definitions
of `foo', where nhc doesn't seem to properly distinguish
that they come from two different modules.

Cheers,
Manuel

PS: In case anybody is wondering, I am still trying to get
    nhc to compile the basic compiler-support libraries that
    I need to port C->Haskell.