这很有效
unique :: (a -> Bool) -> [a] -> Bool
unique p xs = 1 == length (filter p xs)
Run Code Online (Sandbox Code Playgroud)
但现在我想要它的形式:
unique = (== 1) . length . filter
Run Code Online (Sandbox Code Playgroud)
错误信息:
Couldn't match expected type `[a] -> Bool' with actual type `Bool'
Expected type: b0 -> [a] -> Bool
Actual type: b0 -> Bool
In the first argument of `(.)', namely `(== 1)'
In the expression: (== 1) . length . filter
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?