
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























let pick_one n = if n > 0 then (fun x -> x + 1) else (fun x -> x - 1) (pick_one -5) 6 (* returns 5 *)
let sum l = fold ((fun (a, x) -> a + x), 0, l)
let sum l = let add (a, x) = a + x in fold (add, 0, l)
let pick_one n = let add_one x = x + 1 in let sub_one x = x - 1 in if n > 0 then add_one else sub_one
let addN (n, l) =
map (add, l)
let map (f, n) = match n with [] -> [] | (h::t) -> (f h)::(map (f, t))
addN (3, [1; 2; 3])
let add x = n + x in
int x; void f() { x = 3; } void g() { char *x = "hello"; f(); }
let add x = (fun y -> x + y)
(add 3) 4 →
let twice (n, y) = let f x = x + n in f (f y)
twice (3, 4) →
let add x = (fun y -> (fun z -> x + y + z))
(((add 1) 2) 3) → ((
let add x y = x + y
let add = (fun x -> (fun y -> x + y)) let add = (fun x y -> x + y) let add x = (fun y -> x+y)
let rec map f l = match l with [] -> [] | (h::t) -> (f h)::(map f t)
let rec fold f a l = match l with [] -> a | (h::t) -> fold f (f a h) t