键入不匹配期望bool列表但获取int列表

时间:2015-10-28 12:20:33

标签: f#

我将根据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 

我该如何解决?

1 个答案:

答案 0 :(得分:0)

  1. 如@ildjarn所说 - 无效语法
  2. 您的参数顺序错误。 可能,你想这样做:
  3. 示例:

    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