4d9ba6edb6461442c5572c6229841f134e87ee2e
[ghc-hetmet.git] / ghc / compiler / tests / typecheck / should_succeed / tc086.hs
1 {-
2   From: Marc van Dongen <dongen@cs.ucc.ie>
3   Date: Sat, 31 May 1997 19:57:46 +0100 (BST)
4
5    panic! (the `impossible' happened):
6            tcLookupTyVar:a_r6F
7
8    Please report it as a compiler bug to glasgow-haskell-bugs@dcs.gla.ac.uk.
9
10
11 If the instance definition for (*) at the end of this toy module
12 is replaced by the definition that is commented, this all compiles
13 fine. Strange, because the two implementations are equivalent modulo
14 the theory {(*) = multiply}.
15
16 Remove the `multiply :: a -> a -> a' part, and it compiles without
17 problems.
18
19
20 SPJ note: the type signature on "multiply" should be
21         multiply :: Group a => a -> a -> a
22
23 -}
24
25 module Rings( Group, Ring ) where
26
27 import qualified Prelude( Ord(..), Eq(..), Num(..) )
28 import Prelude hiding( Ord(..), Eq(..), Num(..), MonadZero( zero ) )
29
30 class Group a where
31   compare     :: a -> a -> Prelude.Ordering
32   fromInteger :: Integer -> a
33   (+) :: a -> a -> a
34   (-) :: a -> a -> a
35   zero :: a
36   one  :: a
37   zero = fromInteger 0
38   one  = fromInteger 1
39
40 -- class (Group a) => Ring a where
41 -- (*) :: a -> a -> a
42 -- (*) a b =
43 --                  case (compare a zero) of
44 --                    EQ -> zero
45 --                    LT -> zero - ((*) (zero - a) b)
46 --                    GT -> case compare a one of
47 --                            EQ -> b
48 --                            _  -> b + ((*) (a - one) b)
49
50 class (Group a) => Ring a where
51   (*) :: a -> a -> a
52   (*) a b = multiply a b
53           where multiply :: Group a => a -> a ->a 
54                 multiply a b
55                   = case (compare a zero) of
56                       EQ -> zero
57                       LT -> zero - (multiply (zero - a) b)
58                       GT -> case compare a one of
59                               EQ -> b
60                               _  -> b + (multiply (a - one) b)