Functors in Ocaml

不想你离开。 提交于 2019-12-05 01:35:43

You need to change these two lines

module Set (Elt:Ordered) : S = 
module OrdInt : Ordered =

to

module Set (Elt:Ordered) : S with type elt = Elt.t = 
module OrdInt : Ordered with type t = int =

Without these, the modules will not have signatures that expose the types elt and t as int.

[Edit]: The set.ml doesn't have the 'with' bit, because there's a sml.mli, which declares the signature for the functor and it does have the 'with'. Also, OrdInt doesn't need 'with' if you don't explicitly specify a signature for it, like this:

module OrdInt =

You can also construct the set by defining the module in place:

module IntSet = Set (struct
 type t = int
 let lt a b = a < b
 let eq a b = a = b
 let leq a b = a <= b
end) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!