3 ms·
FWIW, this can be inferred fully automatically. Type let pair = fun x -> fun y -> { _0 = x; _1 = y } let rec reduce = fun init -> fun combine -> fun x
by Veedrac 9y ago
FWIW, this can be inferred fully automatically. Type
let pair = fun x -> fun y -> { _0 = x; _1 = y }
let rec reduce = fun init -> fun combine -> fun xs ->
match xs with
[] -> init
| x :: rest -> reduce (combine x init) combine rest
let test = reduce 0 pair [1; 2; 3; 4]
into https://www.cl.cam.ac.uk/~sd601/mlsub/ https://www.cl.cam.ac.uk/~sd601/mlsub/ to see a demonstration.