tests: remove extra_files.py (#12223)
[ghc.git] / testsuite / tests / typecheck / should_fail / tcfail133.hs
1 {-# LANGUAGE UndecidableInstances, FlexibleInstances, TypeOperators,
2 MultiParamTypeClasses, FunctionalDependencies, DatatypeContexts #-}
3
4 -- This one crashed GHC 6.3 due to an error in TcSimplify.add_ors
5
6 module Foo where
7
8 data Zero = Zero deriving Show
9 data One = One deriving Show
10 infixl 9 :@
11 data (Number a, Digit b) => a :@ b = a :@ b deriving Show
12
13 class Digit a
14 instance Digit Zero
15 instance Digit One
16
17 class Number a
18 instance Number Zero
19 instance Number One
20 instance (Number a, Digit b) => Number (a :@ b)
21
22 --- Pretty printing of numbers ---
23 class PrettyNum a where
24 prettyNum :: a -> String
25
26 instance PrettyNum Zero where
27 prettyNum _ = "0"
28
29 instance PrettyNum One where
30 prettyNum _ = "1"
31
32 instance (Number a, Digit b, PrettyNum a, PrettyNum b)
33 => PrettyNum (a :@ b) where
34 prettyNum ~(a:@b)
35 = prettyNum a ++ prettyNum b
36
37 --- Digit addition ---
38 class (Number a, Digit b, Number c)
39 => AddDigit a b c | a b -> c where
40 addDigit :: a -> b -> c
41 addDigit = undefined
42
43 instance Number a => AddDigit a Zero a
44 instance AddDigit Zero One One
45 instance AddDigit One One (One:@Zero)
46 instance Number a => AddDigit (a:@Zero) One (a:@One)
47 instance AddDigit a One a'
48 => AddDigit (a:@One) One (a':@Zero)
49
50 --- Addition ---
51 class (Number a, Number b, Number c)
52 => Add a b c | a b -> c where
53 add :: a -> b -> c
54 add = undefined
55
56 instance Number n => Add n Zero n
57 instance Add Zero One One
58 instance Add One One (One:@One)
59 instance Number n
60 => Add (n:@Zero) One (n:@One)
61 instance AddDigit n One r'
62 => Add (n:@One) One (r':@Zero)
63 instance (Number n1, Digit d1, Number n2, Digit n2
64 ,Add n1 n2 nr', AddDigit (d1:@nr') d2 r)
65 => Add (n1:@d1) (n2:@d2) r
66
67
68 foo = show $ add (One:@Zero) (One:@One)
69
70
71 -- Add (One:@Zero) (One:@One) c, Show c
72 -- ==> Number One, Digit Zero, Number One, Digit One
73 -- Add One One nr', AddDigit (Zero:@nr') One c, Show c
74 --
75 -- ==> Add One One nr', AddDigit (Zero:@nr') One c, Show c
76 --
77 -- ==> Add One One (One:@One), AddDigit (Zero:@(One:@One)) One c, Show c
78 --
79 -- ==> AddDigit (Zero:@(One:@One)) One c, Show c