Overlapping instances vs. Haskell98 Report [was: How to disable warning for "export item 'module ...' exports nothing"?]

Sean Leather leather at cs.uu.nl
Fri Aug 15 11:06:19 EDT 2008


Ross Paterson wrote:

> On Fri, Aug 15, 2008 at 04:17:44PM +0200, Sean Leather wrote:
> > module A where
> > class A t where
> >   a :: t
> >
> > module B where
> > import A
> > instance A Int where
> >   a = 0
> > a0 :: Int
> > a0 = a
> >
> > module C where
> > import A
> > instance A Int where
> >   a = 1
> > a1 :: Int
> > a1 = a
> >
> > module Main where
> > import A
> > import B
> > import C
> > main = do putStrLn $ "a0=" ++ show a0
> >           putStrLn $ "a1=" ++ show a1
> >
> > This works, because of the way the instances are used. While overlapping
> > instances are imported into Main, they are not used in Main.
>
> Then that is a GHC bug.  Haskell 98 Report 4.3.2: "A type may not be
> declared as an instance of a particular class more than once in the
> program."
>

That's interesting. So, maybe there should be some language extension or
warning (with associated -fno-warn) for this in GHC.

Personally, I prefer the way it's done now. (I guess that's obvious,
considering I'm developing a library that will take advantage of it. ;) )
But it makes sense that instances are only looked up when needed, instead of
globally tracked.

Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20080815/fcd50c1b/attachment.htm


More information about the Glasgow-haskell-users mailing list