-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter8.1.idr
50 lines (35 loc) · 1.42 KB
/
chapter8.1.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
48
49
50
module Main
%default total
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
data EqNat : (num1 : Nat) -> (num2 : Nat) -> Type where
Same : (num : Nat) -> EqNat num num
checkEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)
checkEqNat Z Z = pure $ Same 0
checkEqNat Z (S _) = Nothing
checkEqNat (S k) Z = Nothing
checkEqNat (S k) (S j) = (\(Same x) => Same (S x)) <$> checkEqNat k j
exactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)
exactLength {m} len input = (\(Same _) => input) <$> checkEqNat m len
checkEqNat2 : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2)
checkEqNat2 Z Z = pure $ Refl
checkEqNat2 Z (S _) = Nothing
checkEqNat2 (S k) Z = Nothing
checkEqNat2 (S k) (S j) = cong <$> checkEqNat2 k j
exactLength2 : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)
exactLength2 {m} len input = (\Refl => input) <$> checkEqNat2 m len
same_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys
same_cons = cong
same_lists : {xs : List a} -> {ys : List a} -> x = y -> xs = ys -> x :: xs = y :: ys
same_lists Refl = cong
data ThreeEq : a -> b -> c -> Type where
Refl3 : ThreeEq x x x
allSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)
allSameS x x x Refl3 = Refl3
-------
myReverse : Vect n elem -> Vect n elem
myReverse [] = []
myReverse (x :: xs) = myReverse xs ++ [x]
main : IO ()
main = print $ 10