0 | module Decidable.HDecEq
2 | import public Data.List.Quantifiers
3 | import public Data.Maybe0
9 | interface HDecEq a where
10 | constructor MkHDecEq
11 | hdecEq : (x,y : a) -> Maybe0 (x === y)
15 | hdecEq x y = case prim__eq_Bits8 x y of
17 | _ => Just0 (believe_me $
Refl {x})
21 | hdecEq x y = case prim__eq_Bits16 x y of
23 | _ => Just0 (believe_me $
Refl {x})
27 | hdecEq x y = case prim__eq_Bits32 x y of
29 | _ => Just0 (believe_me $
Refl {x})
33 | hdecEq x y = case prim__eq_Bits64 x y of
35 | _ => Just0 (believe_me $
Refl {x})
39 | hdecEq x y = case prim__eq_Int8 x y of
41 | _ => Just0 (believe_me $
Refl {x})
45 | hdecEq x y = case prim__eq_Int16 x y of
47 | _ => Just0 (believe_me $
Refl {x})
51 | hdecEq x y = case prim__eq_Int32 x y of
53 | _ => Just0 (believe_me $
Refl {x})
57 | hdecEq x y = case prim__eq_Int64 x y of
59 | _ => Just0 (believe_me $
Refl {x})
62 | HDecEq Integer where
63 | hdecEq x y = case prim__eq_Integer x y of
65 | _ => Just0 (believe_me $
Refl {x})
69 | hdecEq x y = case prim__eq_Int x y of
71 | _ => Just0 (believe_me $
Refl {x})
75 | hdecEq x y = case prim__eq_Char x y of
77 | _ => Just0 (believe_me $
Refl {x})
81 | hdecEq x y = case prim__eq_String x y of
83 | _ => Just0 (believe_me $
Refl {x})
86 | HDecEq a => HDecEq (Maybe a) where
87 | hdecEq Nothing Nothing = Just0 Refl
88 | hdecEq (Just x) (Just y) = map (\x => cong Just x) (hdecEq x y)
89 | hdecEq _ _ = Nothing0
92 | HDecEq a => HDecEq b => HDecEq (Either a b) where
93 | hdecEq (Left x) (Left y) = map (\x => cong Left x) (hdecEq x y)
94 | hdecEq (Right x) (Right y) = map (\x => cong Right x) (hdecEq x y)
95 | hdecEq _ _ = Nothing0
98 | HDecEq a => HDecEq b => HDecEq (Pair a b) where
99 | hdecEq (x1,y1) (x2,y2) = case hdecEq x1 x2 of
100 | Just0 r1 => case hdecEq y1 y2 of
101 | Just0 r2 => Just0 (cong2 MkPair r1 r2)
102 | Nothing0 => Nothing0
103 | Nothing0 => Nothing0
105 | 0 eqNatToEqual : (x,y : Nat) -> (x == y) === True -> x === y
106 | eqNatToEqual 0 0 p = Refl
107 | eqNatToEqual (S k) (S m) p = cong S $
eqNatToEqual k m p
108 | eqNatToEqual Z (S k) p impossible
109 | eqNatToEqual (S k) Z p impossible
111 | hdecEqNat : (x,y : Nat) -> Maybe0 (x === y)
112 | hdecEqNat x y with (x == y) proof eq
113 | _ | True = Just0 (eqNatToEqual x y eq)
114 | _ | False = Nothing0
121 | HDecEq a => HDecEq (List a) where
122 | hdecEq [] [] = Just0 Refl
123 | hdecEq (h1 :: t1) (h2 :: t2) = case hdecEq h1 h2 of
124 | Just0 r1 => case hdecEq t1 t2 of
125 | Just0 r2 => Just0 (cong2 (::) r1 r2)
126 | Nothing0 => Nothing0
127 | Nothing0 => Nothing0
128 | hdecEq _ _ = Nothing0
131 | (prf : All (HDecEq . f) ks) => HDecEq (All f ks) where
132 | hdecEq [] [] = Just0 Refl
133 | hdecEq {prf = _ :: _} (h1 :: t1) (h2 :: t2) = case hdecEq h1 h2 of
134 | Just0 r1 => case hdecEq t1 t2 of
135 | Just0 r2 => Just0 (cong2 (::) r1 r2)
136 | Nothing0 => Nothing0
137 | Nothing0 => Nothing0
138 | hdecEq _ _ = Nothing0
141 | (p : All (HDecEq . f) ks) => HDecEq (Any f ks) where
142 | hdecEq {p = _ :: _} (Here x) (Here y) = map (\x => cong Here x) $
hdecEq x y
143 | hdecEq {p = _ :: _} (There x) (There y) = map (\x => cong There x) $
hdecEq x y
144 | hdecEq _ _ = Nothing0