summaryrefslogtreecommitdiff
path: root/testdata/typeclass.lc
diff options
context:
space:
mode:
Diffstat (limited to 'testdata/typeclass.lc')
-rw-r--r--testdata/typeclass.lc72
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 #-}
2import Internals
3
4data List a = Nil | Cons a (List a)
5
6infix 4 ==, /=, <
7infixr 3 &&
8infixr 2 ||
9
10not True = False
11not False = True
12
13True && a = a
14False && _ = False
15
16False || a = a
17True || _ = True
18
19class Eq a where
20 (==) :: a -> a -> Bool
21
22a /= b = not (a == b)
23
24instance Eq Bool where
25 True == a = a
26 False == a = not a
27
28instance 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{-
34Ord = \a -> Eq a & Ord' a -- so this is an alias, always subst.
35
36cosmetics:
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
44Ord' Bool = 'Unit
45Ord' [a] = Ord a
46
47todo: mutual recursion
48-}
49{-
50class Eq a => Ord a where
51 (<) :: a -> a -> Bool
52
53instance Ord Bool where
54 _ < False = False
55 b < True = not b
56
57instance Ord a => Ord [a] where
58 a:as < b:bs = a < b || a == b && as < bs
59 _ < [] = False
60 [] < _ = True
61
62
63main = [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