@@ -0,0 +1,105 @@
1+module Decidable.Equality
5+--------------------------------------------------------------------------------
7+--------------------------------------------------------------------------------
9+total negEqSym : {a : t} -> {b : t} -> (a = b -> _|_) -> (b = a -> _|_)
10+negEqSym p h = p (sym h)
13+--------------------------------------------------------------------------------
15+--------------------------------------------------------------------------------
18+ total decEq : (x1 : t) -> (x2 : t) -> Dec (x1 = x2)
20+--------------------------------------------------------------------------------
22+--------------------------------------------------------------------------------
27+instance DecEq () where
28+ decEq () () = Yes refl
30+--------------------------------------------------------------------------------
32+--------------------------------------------------------------------------------
34+total trueNotFalse : True = False -> _|_
35+trueNotFalse refl impossible
37+instance DecEq Bool where
38+ decEq True True = Yes refl
39+ decEq False False = Yes refl
40+ decEq True False = No trueNotFalse
41+ decEq False True = No (negEqSym trueNotFalse)
43+--------------------------------------------------------------------------------
45+--------------------------------------------------------------------------------
47+total OnotS : O = S n -> _|_
50+instance DecEq Nat where
52+ decEq O (S _) = No OnotS
53+ decEq (S _) O = No (negEqSym OnotS)
54+ decEq (S n) (S m) with (decEq n m)
55+ | Yes p = Yes $ cong p
56+ | No p = No $ \h : (S n = S m) => p $ succInjective n m h
58+--------------------------------------------------------------------------------
60+--------------------------------------------------------------------------------
62+total nothingNotJust : {x : t} -> (Nothing {a = t} = Just x) -> _|_
63+nothingNotJust refl impossible
65+instance (DecEq t) => DecEq (Maybe t) where
66+ decEq Nothing Nothing = Yes refl
67+ decEq (Just x') (Just y') with (decEq x' y')
68+ | Yes p = Yes $ cong p
69+ | No p = No $ \h : Just x' = Just y' => p $ justInjective h
70+ decEq Nothing (Just _) = No nothingNotJust
71+ decEq (Just _) Nothing = No (negEqSym nothingNotJust)
73+--------------------------------------------------------------------------------
75+--------------------------------------------------------------------------------
77+total leftNotRight : {x : a} -> {y : b} -> Left {b = b} x = Right {a = a} y -> _|_
78+leftNotRight refl impossible
80+instance (DecEq a, DecEq b) => DecEq (Either a b) where
81+ decEq {b=b} (Left x') (Left y') with (decEq x' y')
82+ | Yes p = Yes $ cong p
83+ | No p = No $ \h : Left x' = Left y' => p $ leftInjective {b = b} h
84+ decEq (Right x') (Right y') with (decEq x' y')
85+ | Yes p = Yes $ cong p
86+ | No p = No $ \h : Right x' = Right y' => p $ rightInjective {a = a} h
87+ decEq (Left x') (Right y') = No leftNotRight
88+ decEq (Right x') (Left y') = No $ negEqSym leftNotRight
90+--------------------------------------------------------------------------------
92+--------------------------------------------------------------------------------
94+total fONotfS : {f : Fin n} -> fO {k = n} = fS f -> _|_
95+fONotfS refl impossible
97+instance DecEq (Fin n) where
98+ decEq fO fO = Yes refl
99+ decEq fO (fS f) = No fONotfS
100+ decEq (fS f) fO = No $ negEqSym fONotfS
101+ decEq (fS f) (fS f') with (decEq f f')
102+ | Yes p = Yes $ cong p
103+ | No p = No $ \h => p $ fSinjective {f = f} {f' = f'} h