News for hackers. Stuff that matters.
Re:I Love OCaml by codesnik on Saturday November 08, 2025 @07:35AM (#45856230)
interesting. how named arguments work with currying?
Re:I Love OCaml by octachron on Saturday November 08, 2025 @10:51AM (#45857534)
Nearly the same as with positional argument: Partially applying a function to a named argument creates a closure with this argument filled in, and you can apply the argument in whichever order you want:

    let f a ~x ~y b = a + x + y + b
    let g = f ~y:1 (* g is closure with the argument named ~y filled in *)
    let h = g 2 (* another closure with the first positional argument filled in *)
    let int_15 = h 8 ~x:4 (* = g 2 8 ~y:4 = f ~y:1 2 8 ~x:4 *)
The more complex interaction is rather with type inference and currying, or the interaction between currying and optional arguments.