-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter8.3.idr
47 lines (35 loc) · 1.44 KB
/
chapter8.3.idr
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
module Main
%default total
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
twoPlusTwoNotFive : 2 + 2 = 5 -> Void
twoPlusTwoNotFive Refl impossible
zeroNotSuc : (0=S k)->Void
zeroNotSuc Refl impossible
sucNotZero : (S k=0)->Void
sucNotZero Refl impossible
noSucc : ((k = j) -> Void) -> (S k = S j) -> Void
noSucc contra Refl = contra Refl
checkEqNat : (num1 : Nat) -> (num2 : Nat) -> Dec (num1 = num2)
checkEqNat Z Z = Yes Refl
checkEqNat Z (S _) = No zeroNotSuc
checkEqNat (S k) Z = No sucNotZero
checkEqNat (S k) (S j) =
case checkEqNat k j of
Yes p => Yes $ cong p
No contra => No $ noSucc contra
vectInjective : {xs : Vect n a} -> {ys : Vect m b} -> x::xs = y::ys -> (x = y, xs = ys)
vectInjective Refl = (Refl, Refl)
headUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} -> (contra : (x = y) -> Void) -> ((x :: xs) = (y :: ys)) -> Void
headUnequal contra prf = contra $ fst $ vectInjective prf
tailUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} -> (contra : (xs = ys) -> Void) -> ((x :: xs) = (y :: ys)) -> Void
tailUnequal contra prf = contra $ snd $ vectInjective prf
DecEq a => DecEq (Vect n a) where
decEq [] [] = Yes Refl
decEq (x :: xs) (y :: ys) = case (decEq x y, decEq xs ys) of
(Yes Refl, Yes Refl) => Yes Refl
(No contraX, _) => No $ headUnequal contraX
(_, No contraY) => No $ tailUnequal contraY
main : IO ()
main = print $ 10