3 | import public Data.DEq
9 | data DOrdering : t -> t -> Type where
20 | -> DOrdering (f x) (f y)
35 | -> (ord : DOrdering x y)
36 | -> DOrdering (f x) (f y)
37 | ordcong f = ordcong' {f}
45 | -> {0 f : t -> tt -> ttt}
46 | -> (lhs : DOrdering a b)
47 | -> (rhs : DOrdering aa bb)
48 | -> DOrdering (f a aa) (f b bb)
49 | precedes DLT _ = DLT
50 | precedes DGT _ = DGT
51 | precedes DEQ DLT = DLT
52 | precedes DEQ DGT = DGT
53 | precedes DEQ DEQ = DEQ
57 | precedes' : Ordering -> DOrdering a b -> DOrdering a b
58 | precedes' LT dord = DLT
59 | precedes' EQ dord = dord
60 | precedes' GT dord = DGT
69 | interface POrd a where
71 | pcompare : (x, y : a) -> DOrdering x y
81 | interface (impl : DEq f) => DOrd (0 f : t -> Type) where
83 | dcompare : f a -> f b -> DOrdering a b
87 | dcompare' : (impl : DOrd f) => f a -> f b -> Ordering
88 | dcompare' fa fb = case dcompare fa fb @{impl} of
96 | implementation [unsafeViaOrd] Ord a => POrd a where
97 | pcompare x y = case compare x y of
100 | EQ => (believe_me $
the (DOrdering x x) DEQ)
103 | implementation POrd Bool where
104 | pcompare x y = pcompare x y @{unsafeViaOrd}
107 | implementation POrd Nat where
108 | pcompare x y = pcompare x y @{unsafeViaOrd}
117 | implementation POrd Int where
118 | pcompare x y = pcompare x y @{unsafeViaOrd}
121 | implementation POrd Integer where
122 | pcompare x y = pcompare x y @{unsafeViaOrd}
125 | implementation POrd Char where
126 | pcompare x y = pcompare x y @{unsafeViaOrd}
129 | implementation POrd String where
130 | pcompare x y = pcompare x y @{unsafeViaOrd}
133 | implementation POrd a => POrd (List a) where
134 | pcompare Nil Nil = DEQ
135 | pcompare (x :: xs) (y :: ys)
136 | = (pcompare x y `precedes` pcompare xs ys) {f = (::)}
137 | pcompare Nil (y :: ys) = DLT
138 | pcompare (x :: xs) Nil = DGT
141 | implementation POrd a => POrd b => POrd (a, b) where
142 | pcompare (a1, b1) (a2, b2)
143 | = (pcompare a1 a2 `precedes` pcompare b1 b2) {f = (,)}