试着学习一些haskell,我知道这个功能
partition :: (a -> Bool) -> [a] -> ([a], [a])
我可以使用递归而不是使用函数。例如,id有我自己定义的函数
partition':: (a -> Bool) -> [a] -> ([a], [a])
将使用递归
答案 0 :(得分:3)
这是一个递归定义:
partition':: (a -> Bool) -> [a] -> ([a], [a])
partition' _ [] = ([],[])
partition' f (x:xs) | f x = (x:matched,notMatched)
| otherwise = (matched,x:notMatched)
where (matched,notMatched) = partition' f xs