Files
2026-08-28 15:50:00 +02:00

22 lines
505 B
Plaintext

(* fml demo: Hindley-Milner inference and evaluation over a few classics. *)
let rec fib = fun n -> if n < 2 then n else fib (n - 1) + fib (n - 2) ;;
fib 10 ;;
let rec map = fun f -> fun xs ->
match xs with
| [] -> []
| h :: t -> f h :: map f t ;;
map (fun x -> x * x) [1; 2; 3; 4; 5] ;;
let compose = fun f -> fun g -> fun x -> f (g x) ;;
let id = fun x -> x ;;
(id 1, id true) ;;
let rec length = fun xs ->
match xs with
| [] -> 0
| _ :: t -> 1 + length t ;;
length [10; 20; 30; 40] ;;