http://caml.inria.fr/pub/docs/manual-ocaml-400/manual021.html#toc79で与えられた例に関する有益なコメントをお待ちしております。
7.12 明示的な多相型注釈
type 'a t = Leaf of 'a | Node of ('a * 'a) t
let rec depth : 'a. 'a t -> 'b = function
|Leaf _ -> 1
| Node x -> 1 + depth x
この例の関数は理解できますが、タイプの「マップのような」関数を定義しようとすると
'a. 'a t -> ('a -> 'b) -> 'b t
例えば:
let rec tmap: 'a. 'a t ->(f:'a->'b) -> 'b t = function
|Leaf x -> Leaf( f x)
|Node x -> let res = tmap x in Node(res);;
次のエラーが表示されます。
Characters 67-77:
|Leaf x -> Leaf( f x)
^^^^^^^^^^
Error: This expression has type 'c t but an expression was expected of type
(f:'a -> 'b) -> 'b t
私は完全に理解していません。有益なコメントをいただければ幸いです。