-
Notifications
You must be signed in to change notification settings - Fork 0
/
vect.mana
49 lines (36 loc) · 1.46 KB
/
vect.mana
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
------------------------------------------------------------------------------
--
-- Vect
--
------------------------------------------------------------------------------
namespace Vect
import Primitive
------------------------------------------------------------------------------
-- Nat
------------------------------------------------------------------------------
type Nat = Z | S Nat
addNat : Nat -> Nat -> Nat
addNat Z m = m
addNat (S n) m = S (addNat n m)
------------------------------------------------------------------------------
-- Vect
------------------------------------------------------------------------------
type Vect : Nat -> Type -> Type where
VNil : Vect Z a
VCons : (x : a) -> (xs : Vect n a) -> Vect (S n) a
head : Vect (S n) a -> a
head (VCons x xs) = x
map : (a -> b) -> Vect n a -> Vect n b
map f (VNil ) = VNil
map f (VCons x xs) = VCons (f x) (map f xs)
zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c
zipWith f (VNil ) (VNil ) = VNil
zipWith f (VCons x xs) (VCons y ys) = VCons (f x y) (zipWith f xs ys)
------------------------------------------------------------------------------
--
------------------------------------------------------------------------------
vs = [ 3, 4, 5 ]
main = do
print vs
print <| map square vs
print <| zipWith (+) [3, 5] [1, 2]