Optional arguments in functions???
"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Wed, 6 Apr 2016 16:00:31 -0500
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAM0XMJTZ6Sp5j=FLgVdeD2g755+tNRuTJWzpLotJLNjh_irOGQ@mail.gmail.com> |
Hi everyone, I'm experiencing some issues with optional arguments passed to functions in Ocaml. For example, let's say I want to write a function like this: let multiply x y ?z(z = 1) = x * y * z ;; This doesn't work in utop. What I'm trying to do is this. If two arguments are passed to the function, then just return the product of those two arguments. ( Because x * y * 1 is always the same as x * y. ) But if three arguments are passed, then return the product of all three integers. What am I doing wrong? There must be a way to do this. Thanks for sharing! Best, Douglas.