オプション引数
$ocaml Objective Caml version 3.09.3 # let f x y = failwith (x^y);; val f : string -> string -> 'a =# (fun g -> g "foo" "bar") f;; Exception: Failure "foobar".
OK。
# let f ?(a=0) x y = x ^ y;; val f : ?a:int -> string -> string -> string = <fun> # (fun g -> g "foo" "bar") f;; - : string = "foobar"
これも OK。しかし次でエラーになる。
# let f ?(a=0) x y = failwith (x^y);; val f : ?a:int -> string -> string -> 'a =# (fun g -> g "foo" "bar") f;; This expression has type ?a:int -> string -> string -> 'a but is here used with type string -> string -> 'b
うーん、これは通ってもいいと思うんだけどなあ。次のようにすると通る。
# (fun g -> g "foo" "bar") (f : ?a:int -> string -> string -> string);; Exception: Failure "foobar".