换句话说,在下面的filter实现中,我可以使用什么语法(如果有)来代替
XXX
?filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
filter' f (x:xs) =
let n = if f x then x else XXX
in n:(filter' f xs)
我知道以下的替代实现(它是递归且仅在前面添加),但如果中缀运算符具有LHS标识符,我仍然很好奇。
filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
filter' f (x:xs)
| f x = x:(filter' f xs)
| otherwise = filter' f xs