0

我正在尝试学习functors在标准 ML 中使用。我已经编写了以下代码,但我不断收到错误消息Error: unmatched structure specification: Element。任何人都可以向我指出错误。我一直找不到它:

signature SET_ELEMENT =
 sig
   type element
   val equal: element -> element -> bool
 end

signature SET =
 sig
   type set
   structure Element : SET_ELEMENT

   val empty: set
   val member: Element.element -> set -> bool
 end

functor Set (Element:SET_ELEMENT) :> SET =
  struct
    type element = Element.element
    type set = element list
    val empty = [];

    fun member x [] = false
      | member x (y::ys) = Element.equal x y orelse member x ys;
  end
4

1 回答 1

1

您声明了一个Element在 的签名中调用的结构SET。然而,您没有定义Element函子输出的结构中调用的结构。

Element只需添加一行声明它与函子的输入相同:

functor Set (Element:SET_ELEMENT) :> SET =
  struct
    structure Element = Element
    type element = Element.element
    type set = element list
    val empty = [];

    fun member x [] = false
      | member x (y::ys) = Element.equal x y orelse member x ys;
  end
于 2012-09-18T19:35:55.400 回答