过滤元组列表

Kev*_*ith -1 haskell

我正在尝试过滤list of 2-tuples第一个元组值等于的位置0:

ghci> ys
[(0,55),(1,100)]

ghci> filter (\x -> x.fst == 0) ys
<interactive>:71:27:
    Couldn't match type `(Integer, Integer)' with `b0 -> c0'
    Expected type: [b0 -> c0]
      Actual type: [(Integer, Integer)]
    In the second argument of `filter', namely `ys'
    In the expression: filter (\ x -> x . fst == 0) ys
    In an equation for `it': it = filter (\ x -> x . fst == 0) ys
Run Code Online (Sandbox Code Playgroud)

我想要的输出:

[(1,100)]

我怎样才能做到这一点?另外,编译时错误是什么意思?

Lei*_*ele 8

(.)是你想要的功能组合filter (\x -> fst x == 0) ys.编辑:您实际需要filter (\x -> fst x /= 0) ys因为filter提供满足谓词的值列表.

编译时错误是抱怨的,因为编译器推断x必须是一个函数,因为你正在编写它fst,但ys不是函数列表.