Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

haskell - I need to read 2 lists to get the difference set to get a third list, where A contains what B = C does not have

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...