LoginSignup
0
0

More than 5 years have passed since last update.

オプショナル引数を使う

Posted at

いつも忘れるので覚え書き。
関数のシグネチャを定義するときに? label:(pattern=default-value)というふうに書くと、オプショナル引数として扱われる。
labelとpatternが同じ時は省略して?(label=default-value)というふうに書けるらしい。

let some_function ?mode:(mode=0) arg1 arg2 = 
(* もしくは ?(mode=1) *)
    (* ... *)
;;

some_function arg1 arg2;;
some_function ~mode:1 arg1 arg2;; (* debug mode *)

使えるラベルは決まってるらしいけど良く分からない。
そもそもこのページみたほうが良い
http://www.geocities.jp/m_hiroi/func/ocaml22.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0