我将根据2个边界过滤int list
。为此,我以这种方式使用了List.filter
:
let CountFilesInRange ele lowerRang upperRange=
match ele with
| ele when lowerRang< ele< upperRange -> true
| _ ->false
List.filter (CountFilesInRange 0 5000) listOfSizes
在最后一行中,listOfSizes
发生了此错误:
Type mismatch expecting bool list but get int list
我该如何解决?
答案 0 :(得分:0)
示例:
let listOfSizes = [1;2;3;4]
let betweenExclusive lowerBound upperBound value =
match value with
| value when lowerBound < value && value < upperBound -> true
| _ -> false
List.filter (betweenExclusive 1 4) listOfSizes |> printfn "%A"
打印:
[2; 3]
链接:
https://dotnetfiddle.net/3179jr
修改强>
感谢@Sehnsucht的评论。此功能可以重写为:
let betweenExclusive lowerBound upperBound value =
lowerBound < value && value < upperBound