Reputation: 17
I am trying to learn using functors
in Standard ML. I have written the following code but I keep getting an error Error: unmatched structure specification: Element
. Can anyone please point out the error to me. I haven't been able to find it:
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
Upvotes: 0
Views: 1425
Reputation: 122439
You declared a structure called Element
in the signature of SET
. Yet you did not define a structure called Element
in the struct that is output by the functor.
Just add a line declaring it to be the same as the Element
input to the functor:
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
Upvotes: 1