-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks.lambo
More file actions
86 lines (71 loc) · 1.59 KB
/
benchmarks.lambo
File metadata and controls
86 lines (71 loc) · 1.59 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
let id λx.x in
let Y λf.
(λx.f (x x))
(λx.f (x x))
in
let true λx y.x in
let false λx y.y in
let and \p q.q p false in
let cons #constructor 2 in
let nil #constructor 0 in
let some #constructor 1 in
let none #constructor 0 in
let option_unwrap
EXHAUSTED
| #match none EMPTY_OPTION
| #match some id
in
let nth Y \nth n.
EXHAUSTED
| #match nil none
| #match cons (\head tail.(=num n 0) (some head) (tail | nth (- 1 n)))
in
let numbers_from Y λnumbers_from n.
cons n (n | + 1 | numbers_from)
in
let >= λthan what.
than | - what | =num 0
in
let mod λmodulus n.
n | (- (n | / modulus | * modulus))
in
let fold \combine zero.
(
Y \fold acc.
EXHAUSTED
| #match nil acc
| #match cons (\head tail.acc | combine head | combine (tail | fold zero))
) zero
in
let map Y \map f.
EXHAUSTED
| #match nil nil
| #match cons (\head tail.cons (head | f) (tail | map f))
in
let find Y \find predicate.
EXHAUSTED
| #match nil none
| #match cons (\head tail.(predicate head) (some head) (tail | find predicate))
in
let primes
let build_primes Y λbuild_primes known_primes start_at.
let next
numbers_from 0
| map (λx.x | * 2 | + start_at)
| (find λn.
known_primes
| map (λprime.n | mod prime | >= 1)
| fold and true
)
| option_unwrap
in
cons next (build_primes (cons next known_primes) (+ 2 next))
in
cons 2 (build_primes (cons 2 nil) 3)
in
let bench_numbers \n.
numbers_from 0 | nth n | option_unwrap
in
let bench_primes \n.
primes | nth n | option_unwrap
in