gpt4 book ai didi

sml - 运算符和操作数不一致[需要相等类型]

转载 作者:行者123 更新时间:2023-12-04 14:03:13 25 4
gpt4 key购买 nike

这个函数计算列表中第y个元素

fun func y xs=List.length(List.filter(fn x => x=y) xs);

val countElement = fn : ''a -> ''a ?.list -> int
func 1 [1,2,3,4];
val it = 1 : int

但是,当我写 func 1.1 [1.1,2.1,3.1,4.1];我收到错误:

stdIn:64.1-64.35 Error: operator and operand don't agree [equality type required]
operator domain: ''Z
operand: real
in expression:
countElement 1.1

我该如何解决这个问题?

最佳答案

real 在 SML 97 中不是相等类型。这意味着您不能使用 = 来比较两个 real

关于sml - 运算符和操作数不一致[需要相等类型],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32097751/

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