diff options
Diffstat (limited to 'testdata/typeclass.lc')
-rw-r--r-- | testdata/typeclass.lc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testdata/typeclass.lc b/testdata/typeclass.lc new file mode 100644 index 00000000..7f432f64 --- /dev/null +++ b/testdata/typeclass.lc | |||
@@ -0,0 +1,72 @@ | |||
1 | {-# LANGUAGE NoImplicitPrelude #-} | ||
2 | import Internals | ||
3 | |||
4 | data List a = Nil | Cons a (List a) | ||
5 | |||
6 | infix 4 ==, /=, < | ||
7 | infixr 3 && | ||
8 | infixr 2 || | ||
9 | |||
10 | not True = False | ||
11 | not False = True | ||
12 | |||
13 | True && a = a | ||
14 | False && _ = False | ||
15 | |||
16 | False || a = a | ||
17 | True || _ = True | ||
18 | |||
19 | class Eq a where | ||
20 | (==) :: a -> a -> Bool | ||
21 | |||
22 | a /= b = not (a == b) | ||
23 | |||
24 | instance Eq Bool where | ||
25 | True == a = a | ||
26 | False == a = not a | ||
27 | |||
28 | instance Eq t => Eq [t] where | ||
29 | [] == [] = True | ||
30 | (==) (a:as) (b:bs) = a == b -- && as == bs | ||
31 | -- TODO a:as == b:bs = a == b && as == bs | ||
32 | _ == _ = False | ||
33 | {- | ||
34 | Ord = \a -> Eq a & Ord' a -- so this is an alias, always subst. | ||
35 | |||
36 | cosmetics: | ||
37 | |||
38 | - subst. Ord' with Ord when presented to the user | ||
39 | - omit Eq whereever possible | ||
40 | - mark Ord-stemmed Eq as 'derived' | ||
41 | - 'derived' Eq overcomes other Eq | ||
42 | - eliminate all 'derived' Eq | ||
43 | |||
44 | Ord' Bool = 'Unit | ||
45 | Ord' [a] = Ord a | ||
46 | |||
47 | todo: mutual recursion | ||
48 | -} | ||
49 | {- | ||
50 | class Eq a => Ord a where | ||
51 | (<) :: a -> a -> Bool | ||
52 | |||
53 | instance Ord Bool where | ||
54 | _ < False = False | ||
55 | b < True = not b | ||
56 | |||
57 | instance Ord a => Ord [a] where | ||
58 | a:as < b:bs = a < b || a == b && as < bs | ||
59 | _ < [] = False | ||
60 | [] < _ = True | ||
61 | |||
62 | |||
63 | main = [False, True] == [False, True] | ||
64 | && [False, True] /= [False, False] | ||
65 | && [False, True] /= [False] | ||
66 | && False < True | ||
67 | && not (False < False) | ||
68 | && [False] < [False, True] | ||
69 | && [[False]] < [[False], []] | ||
70 | -} | ||
71 | |||
72 | |||