I executed the following command in utop with Jane street Base library installed
open Base;;
List.fold;;
It prints
- : 'a list -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accum = <fun>
I interpret this as the fold function first parameter is a list of values. second is the initial value and 3rd is the fold function. The folder function whose first parameter is the accumulator and second parameter is the item from the list being folded.
With this interpretation I write this code
List.fold [Some 1; None; None; Some 2] 0 (fun accm x -> match x with | None -> accum | Some x -> accum + x)
This doesn't work and it prints something weird on the screen
- : init:(int -> (int -> int option -> int) -> '_weak2) ->
f:((int -> (int -> int option -> int) -> '_weak2) ->
int option -> int -> (int -> int option -> int) -> '_weak2) ->
'_weak2
= <fun>
Now If I change my code in utop to use named parameters
List.fold [Some 1; None; Some 2] ~init:0 ~f:(fun accum x -> match x with | None -> accum | Some x -> accum + x);;
Now it works. What's going on? I passed the parameters in the same order as the documented signature suggested? then why am I being forced to use named parameters?