[Haskell] Separate Namespaces and Type Classes

Stephan Herhut S.A.Herhut at herts.ac.uk
Thu Jul 8 07:08:16 EDT 2004

Hi all,

I am pretty new to haskell, but while exploring the haskell module 
system, I came along some questions. As far as I found out, haskell 
supports separated namespaces, i.e. every module has its own symbol 
space. Thus, when defining a class in one module like

module A(Foo(f)) where

class Foo a where
  f ::  a -> Integer

one should be able to define two instances having the same signature, as 
long as they are in different namespaces

module B(bar) where
import A(Foo(f))

instance Foo Integer where
  f x = x

bar x = f x

module C(tango)
import A(Foo(f))

instance Foo Integer where
  f x = x + 1

tango x = f x

As the integer instances of Foo are in separate modules and thus 
namespaces, one should be able to just import bar and tango

module Main(main)
import B(bar)
import C(tango)

main = print( (bar 5) + (tango 4) )

But now, ghc complains about two instances of Foo Integer, although 
there should be none in the namespace main.
I have not found any documentation on why ghc behaves like this and 
whether this conforms to the haskell language specification.
Is there any haskell compiler out there that is able to compile the 
above example?

Thanks for your help

More information about the Haskell mailing list