我的问题看起来很简单,但我似乎无法在任何地方找到答案。我不确定 sml 中的类型 int 和 [int ty] 之间有什么区别。尝试使用 int 元组列表作为我的函数的输入时出现 [tycon mismatch] 错误。例如:
输入:number_in_month ((1993, 2, 2), (1776, 7 4), (1994, 7, 5)) 7;
Error: operator and operand don't agree [tycon mistmatch]
operator domain: (int * int * int) list * int
operand: ([int ty] * [int ty] * [int ty]) *
([int ty] * [int ty] * [int ty]) *
([int ty] * [int ty] * [int ty])
我已经尝试了几种方法来将我的输入括起来,但似乎没有任何改变结果。
最佳答案
SML/NJ(这看起来像是一条错误消息)使用 [int ty]
(在诊断中)表示对应于重载类 Int的整型集
。您可以查看 SML 的修订定义 ('97) 的附录 E 以获取更多信息,但这与您的问题并没有真正的关系。
如果仔细观察,您会发现 number_in_month
的域是 (int * int * int) list * int
,但您为它提供了一个三元组 int
三元组 --- 这应该是 int
三元组的列表。此外,您尝试以柯里化(Currying)的方式传递另一个参数,但我们可以看到它应该在这个列表的元组中,而不是基于这个错误。
相应地你可能想要
number_in_month ([(1993, 2, 2), (1776, 7 4), (1994, 7, 5)], 7)
相反。
关于syntax - 在 sml 中键入 int 与 [int ty],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65854907/