I had a look.  It turns out to be an utterly bogus and incorrect test
for overlap in 6.2.

As it happens, I've already re-written that part of the compiler in the
HEAD, to do lazy overlap resolution.  In GHC 6.2 the instances
        instance C a Bool
        instance C Bool a
are rejected because they overlap (unless you have
-fallow-overlapping-instances).  In GHC HEAD the instances are not
rejected.  Reason: if we are seeking an instance declaration matching (C
Bool Int) then plainly only one of the instances match.  

So GHC HEAD reports overlap only if a lookup finds two matching
instances, rather than when the instance declarations themselves are
declared.  Kind of like lazy reporting of overlap of unqualified names
in the module system.

Anyway, it happens that I'd inadvertently thereby fixed the bug you
found.  Since it's rather a dark corner, I don't propose to fix it for
6.2.

Thanks for reporting it though.

Simon

| -----Original Message-----
| From: [EMAIL PROTECTED]
[mailto:glasgow-haskell-users-
| [EMAIL PROTECTED] On Behalf Of Mike Gunter
| Sent: 06 March 2004 06:13
| To: [EMAIL PROTECTED]
| Subject: Overlapping instances and multi-parameter classes
| 
| 
| 
| Given the following:
| 
| >
| > import Data.Maybe   ( fromMaybe )
| >
| > data None
| > none = error "none evaluated" :: None
| 
| these class and instance declarations:
| 
| > class    ToMaybe2 b    a where toMaybe2   :: a -> Maybe b
| > instance ToMaybe2 a None where toMaybe2 = const Nothing
| > instance ToMaybe2 a    a where toMaybe2 = Just
| 
| compile fine (given -fallow-undecidable-instances and
| -fallow-overlapping-instances).  And the following code:
| 
| > mbPutStrLn  :: ToMaybe2 String a => a -> IO ()
| > mbPutStrLn  = putStrLn . fromMaybe "None." . toMaybe2
| > main = mbPutStrLn none >> mbPutStrLn "Hello, world!"
| 
| works as I'd expect.  However, if the parameters to the class
| are reversed:
| 
| > {- uncomment to see error message
| > class    ToMaybe1 a    b where toMaybe1   :: a -> Maybe b
| > instance ToMaybe1 None a where toMaybe1 = const Nothing
| > instance ToMaybe1 a    a where toMaybe1 = Just
| > -}
| 
| I get the following error message (from GHC{,i} 6.2):
| 
|     Overlapping instance declarations:
|       OverlapOrder.lhs:27: ToMaybe1 None a
|       OverlapOrder.lhs:28: ToMaybe1 a a
| 
| Why is this?
| 
|       thanks,
|       mike
| _______________________________________________
| Glasgow-haskell-users mailing list
| [EMAIL PROTECTED]
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to