# Passing down optional arguments

**URL:** <https://discuss.ocaml.org/t/passing-down-optional-arguments/11574>\
**Category:** Learning\
**Created:** [March 3, 2023, 6:03pm UTC](https://discuss.ocaml.org/t/passing-down-optional-arguments/11574 "2023-03-03T18:03:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mimoo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mimoo/32/2900_2.png) [@mimoo](https://discuss.ocaml.org/u/mimoo)\
**Post date:** [March 3, 2023, 6:03pm UTC](https://discuss.ocaml.org/t/passing-down-optional-arguments/11574/1 "2023-03-03T18:03:21Z")

</div>

imagine I have two nested functions that both take the same optional argument:

```ocaml
let fn1 ?opt _ = _

let fn2 ?opt _ = match opt with Some opt -> fn1 ~opt () | None -> fn1 ()

```

is there a way of writing this more nicely? I was hopping something like that would have just worked but no luck:

```ocaml
let fn1 ?opt _ = _

let fn2 ?opt _ = fn1 ~opt

```

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [March 3, 2023, 6:22pm UTC](https://discuss.ocaml.org/t/passing-down-optional-arguments/11574/2 "2023-03-03T18:22:13Z")

</div>

```ocaml
let fn2 ?opt = fn1 ?opt

```

---

<div class="post-metadata">

**Author:** ![mimoo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mimoo/32/2900_2.png) [@mimoo](https://discuss.ocaml.org/u/mimoo)\
**Post date:** [March 3, 2023, 6:34pm UTC](https://discuss.ocaml.org/t/passing-down-optional-arguments/11574/3 "2023-03-03T18:34:23Z")

</div>

Oh that’s awesome! I have more questions now 😃 does this `?` operator have a name when used as an expression? Is there more usecases for that?

---

<div class="post-metadata">

**Author:** ![vlaviron](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vlaviron](https://discuss.ocaml.org/u/vlaviron)\
**Post date:** [March 3, 2023, 6:54pm UTC](https://discuss.ocaml.org/t/passing-down-optional-arguments/11574/4 "2023-03-03T18:54:57Z")

</div>

It’s not an operator, it’s syntax. It is used like `~`, but for optional parameters only and assumes that the corresponding variable already has an option type.  
Example:

```auto
let f1 ?(opt = 42) () = ignore (opt + 1)
let _ =
  f1 ~opt:0 (); (* Pass an actual value *)
  f1 ?opt:(Some 1) (); (* Pass an actual value through an option *)
  f1 ?opt:(None) (); (* Explicitly set no value; default will be used if any *)
  let opt = Some 3 in
  f1 ?opt () (* Punning *)

```
