2
我想编写一个类似的集合如下。如何实现sml的类型?
signature COMPARABLE_SET=
sig
type 'a set
val empty: 'a set
val insert: 'a * 'a set -> 'a set
val member: 'a * 'a set -> bool
end
我需要限制元件在“的一组类型是可比较:(存在与类型的函数:'a * 'a -> order
)。
如何实现它?
看看如何定义SML/NJ库中的ORD_SET签名:http://www.smlnj.org/doc/smlnj-lib/Manual/ord-set.html#ORD_SET:SIG: SPEC –
另外,您想要的内容不能以SML中的安全方式书写。我撰写了两篇与此主题相关的博文:http://igstan.ro/posts/2017-04-08-a-safe-type-indexed-set-for-standard-ml.html和http:// igstan.ro/posts/2017-04-12-a-safe-type-indexed-set-for-standard-ml-errata.html。 –