【问题标题】:Why is this function type "ill-typed"为什么这个函数类型是“错误类型的”
【发布时间】:2020-01-29 07:15:32
【问题描述】:

给定一个带有val add : ’a -> ’a set -> ’a set的接口,为什么输入add 3 [1]没有类型检查?我以为它的类型是int set

【问题讨论】:

    标签: types functional-programming set ocaml


    【解决方案1】:

    好吧,[1] 的类型是 int list,而不是 int set。如果您显示更多 Set 界面,我们可能会提供更多帮助。

    通常一组接口有Set.emptySet.singleton。因此,您的示例可能编码为add 3 (singleton 1)add 3 (add 1 empty)

    【讨论】:

    • 模块提到:val empty : ’a setval is_empty : ’a set -> bool。你指的是这个吗?
    • empty: 'a set:是的,这就是我在我的例子中所说的empty 的意思。 is_empty 是另外一回事——它是一个判断集合是否为空的函数。
    猜你喜欢
    • 1970-01-01
    • 2021-08-09
    • 2020-03-06
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2010-10-27
    相关资源
    最近更新 更多