osiire’s blog

ふしぎなそふとやさん

fully transparent higher-order modules

OCamlはファンクター適用の型を複数のモジュールに渡って透過的に単一化してくれる。SMLのモジュールシステムとは異なるので注意。詳細は原論文"Applicative functors and fully transparent higher-order modules"かhttp://www.cs.cmu.edu/~rwh/courses/modules/slides/applicative.pdf(解説スライド)を参照の事。
要するに、

 functor Dict( Key:Order ) = sig
   ...
   val domain : dict -> Set(Key).t
 end
 functor PrioQueue( Elt:Order ) = sig
   ...
   val contents : queue -> Set(Elt).t
 end

という二つのファンクターがあった時に、DictとPrioQueueに与えられたパラメーターモジュールが同じモジュールなら、Set(Key).tとSet(Elt).tの型は同じと判断されるという訳。これ、同じと判断されないと困るでしょ?
というか、これができるってすごい!分割コンパイルと組み合わせて考えると超便利。