■
# let f = generic :int->int->int => fun x y -> x+y |:int->int => fun x -> x;; val f : [| int -> int -> int | int -> int |] = <generic>
int->int->intとint->intがある関数に、intを一つだけ与えるとどうなるのか試してみる。
# f 1;; - : { int -> 'a < [| int -> int -> int | int -> int |] } => 'a = <generic> # f 1 2;; Warning X: this argument will not be used by the function. - : { int -> int -> 'a < [| int -> int -> int | int -> int |] } => 'a = <generic> # f 1 2 3;; Warning X: this argument will not be used by the function. Warning X: this argument will not be used by the function. - : { int -> int -> int -> 'a < [| int -> int -> int | int -> int |] } => 'a = <generic>
うーん…genericになってしまうのは、なんとかして欲しいなあ。引数3個でもきちんと評価できてしまうし…もしかして返り値をさらに単一化するプログラムだと、うまく型付けできるかな。
# (f 1) = 1;; - : bool = true # (f 2) = 1;; - : bool = false # (f 1 2) = 3;; Warning X: this argument will not be used by the function. - : bool = true # (f 1 2 3)=123;; Warning X: this argument will not be used by the function. Warning X: this argument will not be used by the function. Type int -> int -> int -> int is not an instance of overloaded type [| int -> int -> int | int -> int |].
正解。なんかwarningが気持ち悪い。will not beじゃなくてmay not beとかが正しいと思うけど。
しっかし制約が読めねー