我想在ML中编写一个简单的过滤函数。这个想法是函数only_capitals
接受一个字符串列表并返回一个字符串列表,只有以大写字母开头的字符串。下面是我的实现,但我得到一个类型错误,我不明白:ML List.filter中的类型不匹配
fun only_capitals (strs : string list) =
let
fun isCapitalized (str) = Char.isUpper(String.sub(str, 0))
in
List.filter(isCapital, strs)
end
以下是错误:
hw3provided.sml:5.18-5.27 Error: unbound variable or constructor: isCapital
hw3provided.sml:5.6-5.34 Error: operator and operand don't agree [tycon mismatch]
operator domain: 'Z -> bool
operand: _ * string list
in expression:
List.filter (<errorvar>,strs)
val it =() : unit
那么,有什么错误? – melpomene