-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbasic.law
57 lines (42 loc) · 1.14 KB
/
basic.law
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
51
52
53
54
55
56
57
ob Base Bool = [ true: {}, false: {} ]
ar not : Bool --> Bool =
[ true = {} false.,
false = {} true. ]
ar and : (Bool, Bool) --> Bool =
@1 [ true = .2,
false = {} false. ]
ob Base ListInt =
[ empty: {},
cons: { head: Int, tail: ListInt }
]
ar length : ListInt --> Int =
[ empty = 0,
cons = ( 1, .tail length ) plus ]
ob Base ListListInt =
[ empty: {},
cons: { head: ListInt, tail: ListListInt }
]
ar map : (ListInt => Int, ListListInt) --> ListInt =
{ f = .1, xs = .2 }
@xs
[ empty = {=} empty.,
cons = { head = ( .f, .xs .head ) app,
tail = ( .f, .xs .tail ) map }
cons. ]
ar mapLength : ListListInt --> ListInt =
(const(length), ) map
ar main : {} --> ListInt =
listOfLists mapLength
// Some lists follow
ar cons1 : ListInt --> ListInt =
{ head = 100, tail = } cons.
ar cons2 : ListInt --> ListInt =
{ head = 200, tail = } cons.
ar list3 : {} --> ListInt =
empty. cons1 cons2 cons1
ar list2 : {} --> ListInt =
empty. cons2 cons1 cons1 cons1
ar listOfLists : {} --> ListListInt =
empty.
{ head = {} list3, tail = } cons.
{head = {} list2, tail = } cons.