[ACCEPTED]-OCaml: Default values for function arguments?-default-value
Accepted answer
OCaml doesn't have optional positional parameters, because, since 10 OCaml supports currying, if you leave out 9 some arguments it just looks like a partial 8 application. However, for named parameters, there 7 are optional named parameters.
Normal named 6 parameters are declared like this:
let foo ~arg1 = arg1 + 5;;
Optional 5 named parameters are declared like this:
let odp ?(ftw = "OMG!!") () = print_endline ftw;;
(* and can be used like this *)
odp ~ftw:"hi mom" ();;
odp ();;
Note 4 that any optional named parameters must 3 be followed by at least one non-optional 2 parameter, because otherwise e.g "odp" above 1 would just look like a partial application.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.