-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVectorUtils.idr
46 lines (36 loc) · 1.15 KB
/
VectorUtils.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
module VectorUtils
import Data.Vect
export
is_empty_implicit : {n: Nat} -> Vect n a -> Bool
is_empty_implicit {n = Z} vect = True
is_empty_implicit {n = (S k)} vect = False
export
is_empty_all_implicit : {n: Nat} -> {a : Type} -> Vect n a -> Bool
is_empty_all_implicit {n = Z} {a = at} vect = True
is_empty_all_implicit {n = (S k)} {a = at} vect = False
export
is_empty_all_implicit_in_decl : {n: Nat} -> {a : Type} -> Vect n a -> Bool
is_empty_all_implicit_in_decl {n = Z} vect = True
is_empty_all_implicit_in_decl {n = (S k)} vect = False
export
is_empty : Vect n a -> Bool
is_empty [] = True
is_empty (x :: xs) = False
export
len_from_type : {n : Nat} -> Vect n a -> Nat
len_from_type {n} vect = n
export
total len_implicit : {n : Nat} -> Vect n a -> Nat
len_implicit {n = Z} [] = 0
len_implicit {n = (S k)} (x :: xs) = 1 + len_implicit xs
export
total len : Vect n a -> Nat
len [] = 0
len (x :: xs) = 1 + len xs
export
total my_take : (n : Nat)-> Vect (n + m) t -> Vect n t
my_take Z vect = []
my_take (S k) (x :: xs) = x :: (take k xs)
total get_by_index : Vect k a -> Fin k -> a
get_by_index (x :: xs) FZ = x
get_by_index (y :: xs) (FS k) = get_by_index xs k