gpt4 book ai didi

sml - Standard ML 中的 eqtype 是什么?

转载 作者:行者123 更新时间:2023-12-05 06:27:08 25 4
gpt4 key购买 nike

在下面给定的代码中,eqtype 是什么意思?我知道 SML 中存在一个 type 关键字,它可以让您为类型设置别名,但 eqtype 对我来说是新东西。

signature SYMBOL =
sig
eqtype symbol
val symbol : string -> symbol
val name : symbol -> string
type 'a table
val empty : 'a table
val enter : 'a table * symbol * 'a -> 'a table
val look : 'a table * symbol -> 'a option
end

我试图在文档中找到解释,但找不到任何相关内容。谁能给我解释一下?谢谢。

直觉上,eqtype 似乎让您声明了一个类型,我们需要在创建此签名的结构时指定该类型。

最佳答案

eqtype 是相等类型的关键字。 sml 中的相等类型定义为可以与 = 进行比较的值类型。例如int、string list、bool * bool option都是相等类型,而real、int -> int则不是。

在签名中,当您拥有 eqtype 时,您将添加一个额外的约束层,告诉 sml 该类型是相等类型。任何归因于此签名的结构都需要将类型定义为相等类型。

关于sml - Standard ML 中的 eqtype 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55520914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com