functor適用するときtypeに直接record型を定義すると怒られる件

↑のpostで引っかかったので単純な形にして確認してみた。

  • functor.ml (functorの定義)
komamitsu@carrot:~/lab/ocaml$ cat functor.ml
module type HogeType = sig
  type t
  val string_of_t : t -> string
end

module Make(Hoge : HogeType) = struct
  let print_t t = print_endline (Hoge.string_of_t t)
end
  • functorSample.ml (functor適用)
module RecordSample = Functor.Make(
  struct
    type t = {x:int}
    let string_of_t t = string_of_int t.x
  end
)

let _ =
  RecordSample.print_t {x=4321}

これをコンパイルすると...

komamitsu@carrot:~/lab/ocaml$ ocamlc -o functorSample functor.ml functorSample.ml
File "functorSample.ml", line 1, characters 22-115:
Error: This functor has type
       functor (Hoge : Functor.HogeType) ->
         sig val print_t : Hoge.t -> unit end
       The parameter cannot be eliminated in the result type.
        Please bind the argument to a module identifier.

と怒られてしまう。

type tt = {x:int}
module RecordSample = Functor.Make(
  struct
    type t = tt
        :

とするとOK... 不思議だ...


2011-12-18 11:07 追記id:osiireさんからのコメントで気がついたけれど、functorSample.mlを以下のようにして、scope外で使わないようにしても同じエラーが出る...

module RecordSample = Functor.Make(
  struct
    type t = {x:int}
    let string_of_t t = string_of_int t.x
  end
)