【发布时间】:2015-08-20 16:13:06
【问题描述】:
这个函数计算列表中元素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
我该如何解决这个问题?
【问题讨论】: