大家好,我是Haskell的新手,还在学习,为什么这不起作用呢?
filterFirst :: (a -> Bool) -> [a] -> [a]
filterFirst p xs = delete (not . p) (filter (not . p) xs)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我怎样才能改变这一点,这样我就不需要改变(一个-> Bool)了?
发布于 2013-09-27 22:28:36
delete的第一个参数应该是列表的元素(在本例中是a类型的值),而不是a -> Bool类型的函数。
您得到的类型错误告诉您not . p具有类型a -> Bool,但是delete函数需要一个a类型的值。
发布于 2013-09-27 22:56:14
您可以使用deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]。
https://stackoverflow.com/questions/19053251
复制相似问题