我的任务是重新实现这个功能
divn :: Integer -> [Integer] -> [Integer]
divn _ [] = []
divn n (x:xs) | mod x n == 0 = x : divn n xs
| otherwise = divn n xs
使用“文件夹”。我做了什么:
divn' _ [] = []
divn' n (x:xs) = foldr (\x -> if (mod x n == 0) (x:) ([]++)) [] xs
我以为这会奏效。实际上它甚至没有编译,而是说:“输入时解析错误“)”。
由于我没有发现任何错误,我决定重新编写,好像现在它正在工作......
if' True x _ = x
if' False _ x = x
divn' _ [] = []
divn' n (x:xs) = foldr (\x -> if' (mod x n == 0) (x:) ([]++)) [] xs
有谁知道错误在哪里?
谢谢!