I have this code:
dif :: [Int] -> [Int] -> [Int]
dif [] [] = []
dif (lista) (l:ls) = fun2 lista l
fun2 :: [Int] -> Int -> [Int]
fun2 [] p = []
fun2 (x:y:zs) p = if p==x then fun2 zs p else x:fun2 zs p
If I enter
> dif [1,3,5,7] [2,3,4,5]
the result is [1,5]
. We see that the number 5 is not read from the second list.
If I try to get it with
fun2 (x:y:c:zs) p = if p==x then fun2 zs p else x:fun2 zs p
to read the 5, I get back an error
[1*** Exception: pro.hs:(12,1)-(13,59): Non-exhaustive patterns in function fun2
question from:
https://stackoverflow.com/questions/65948939/i-need-to-read-2-lists-to-get-the-difference-set-to-get-a-third-list-where-a-co 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…