Commit 978160d2 authored by POTTIER Francois's avatar POTTIER Francois

Programming project: expose 4 new test files.

parent 0ff4d675
0
0
1
1
2
0
3
1
4
0
5
1
6
0
7
1
8
0
9
1
10
0
11
1
12
0
13
1
14
0
15
1
16
0
17
1
18
0
19
1
20
0
let pair = fun a1 -> fun a2 -> fun f -> f a1 a2 in
let fst = fun p -> p (fun a1 -> fun a2 -> a1) in
let snd = fun p -> p (fun a1 -> fun a2 -> a2) in
let unit = 0 in
let true = 0 in
let false = 1 in
let rec evenodd = fun unit ->
pair (fun n -> ifzero n then true else snd (evenodd unit) (n-1))
(fun n -> ifzero n then false else fst (evenodd unit) (n-1)) in
let even = fst (evenodd unit) in
let rec print_even_until = fun n ->
let rec print_from = fun i ->
ifzero (n-i)
then let _ = print i in
print (even i)
else let _ = print i in
let _ = print (even i) in
print_from (i+1) in
print_from 0 in
print_even_until 20
let nil = fun f -> fun seed -> seed in
let cons = fun h -> fun t -> fun f -> fun seed -> t f (f seed h) in
let rev = fun l -> l (fun seed -> fun h -> cons h seed) nil in
let rec map_rev = fun f -> fun l -> l (fun seed -> fun h -> cons (f h) seed) nil in
let map = fun f -> fun l -> rev (map_rev f l) in
let printlist = fun l -> l (fun seed -> fun h -> print h) 0 in
let pair = fun a1 -> fun a2 -> fun proj -> proj a1 a2 in
let fst = fun p -> p (fun a1 -> fun a2 -> a1) in
let snd = fun p -> p (fun a1 -> fun a2 -> a2) in
let hd = fun l -> (rev l) (fun seed -> fun h -> h) 0 in
let tl = fun l ->
let tlandl = (rev l) (fun p -> fun h -> pair (snd p) (cons h (snd p))) (pair nil nil) in
fst tlandl in
let l = cons 1 (cons 2 (cons 3 nil)) in
let _ = print (hd l) in
let _ = print (hd (tl l)) in
let _ = print (hd (tl (tl l))) in
printlist (map (fun x -> 3 * x) l)
let add = fun x -> fun y -> x + y in
print (add (print 1) (print 2))
(* should print 3; 2,
but could print something else
if there is variable capture *)
let x = 2 in
let y = x in
let z = x in
let y = 3 in
let _ = print y in
let x = 4 in
let _ = print z in
0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment