yet another very simple overlapping instance example

Razvan Musaloiu-E. razvanm@mail.com
Wed, 25 Jun 2003 13:38:01 +0800


Hi!

Can somebody explain to me why ghc/hugs fails to compile the following 
Haskell program? As long as MyInt is not an instance of Num the 
compilations should succed... but it don't. :-( Why?

$ cat multi.hs
data MyInt = MyInt Int deriving Show

class Op_plus a b where
     plus :: a -> b -> Int

instance Op_plus MyInt MyInt where
     (MyInt a) `plus` (MyInt b) = a + b

instance (Num a) => Op_plus a MyInt where
     i `plus` (MyInt b) = i + b

instance (Num a) => Op_plus MyInt a where
     (MyInt b) `plus` i = i + b

$ ghci						\
	-fglasgow-exts				\
	-fallow-overlapping-instances		\
	-fallow-undecidable-instances multi.hs

    ___         ___ _
   / _ \ /\  /\/ __(_)
  / /_\// /_/ / /  | |   GHC Interactive, version 5.04.2, for Haskell 98.
/ /_\\/ __  / /___| |   http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|   Type :? for help.

Loading package base ... linking ... done.
Loading package haskell98 ... linking ... done.
Compiling Main             ( multi.hs, interpreted )

multi.hs:1: Warning: No 'main' defined in module Main

Overlapping instance declarations:
   multi.hs:9: Op_plus a MyInt
   multi.hs:12: Op_plus MyInt a
Failed, modules loaded: none.
Prelude>

Thanks and regards,
Razvan ME