summaryrefslogtreecommitdiff
path: root/testdata/typeclass.lc
blob: 1104833022366bfcd05cd1b708898eaa626d76a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{-# LANGUAGE NoImplicitPrelude #-}
import Internals hiding ('Eq, (==))

infix 4 ==, /=, <
infixr 3 &&
infixr 2 ||

not True = False
not False = True

True && a = a
False && _ = False

False || a = a
True || _ = True

class Eq a where
    (==) :: a -> a -> Bool

a /= b = not (a == b)

instance Eq Bool where
    True == a = a
    False == a = not a

[]   ==. []   = True
(a:as) ==. (b:bs) = {-a == b && -} as ==. bs
_    ==. _    = False
{-
instance Eq t => Eq [t] where
    []   == []   = True
    a:as == b:bs = a == b && as == bs
    _    == _    = False
-}
{-
Ord = \a -> Eq a & Ord' a       -- so this is an alias, always subst.

cosmetics:

-   subst. Ord' with Ord when presented to the user
-   omit Eq whereever possible
    -   mark Ord-stemmed Eq as 'derived'
    -   'derived' Eq overcomes other Eq
    -   eliminate all 'derived' Eq

Ord' Bool = 'Unit
Ord' [a] = Ord a

todo: mutual recursion
-}
{-
class Eq a => Ord a where
    (<) :: a -> a -> Bool

instance Ord Bool where
    _ < False = False
    b < True = not b

instance Ord a => Ord [a] where
    a:as < b:bs  =  a < b || a == b && as < bs
    _ < []   = False
    [] < _   = True


main = [False, True] == [False, True]
  &&   [False, True] /= [False, False]
  &&   [False, True] /= [False]
  &&   False < True
  &&   not (False < False)
  &&   [False] < [False, True]
  &&   [[False]] < [[False], []]
-}