嗨,大家好,我和Haskell相比,还在学习,所以为什么这不起作用?
filterFirst :: (a -> Bool) -> [a] -> [a]
filterFirst p xs = delete (not . p) (filter (not . p) xs)
Run Code Online (Sandbox Code Playgroud)
当我在终端中收到以下错误消息时:
ERROR "FirstLiterate.lhs":58 - Type error in application
*** Expression : delete (not . p) (filter (not . p) xs)
*** Term : not . p
*** Type : a -> Bool
*** Does not match : a
*** Because : unification would give infinite type
Run Code Online (Sandbox Code Playgroud)
所以我认为类型与我的定义中的类型不匹配.我怎么能改变这个以便我不必改变(a - > Bool)?
第一个参数delete应该是列表的元素(在这种情况下,类型的值a),而不是类型的函数a -> Bool.
您获得的类型错误告诉您not . p具有类型a -> Bool,但该delete函数期望值为type a.