In haskell I'm trying to acheive to convert a list like [(1,2),(3,4),(5,6)] into two lists: [1,3,5] and [2,4,6] using a recursive function only
I tried this so far, but it doesn't work
unpair :: [(a,b)] -> ([a], [b]) unpair [] = [] unpair ((x,y):xs) = x : unpair(xs) y : unpair (xs) however, when I only try to make a list of the first value in the tuples, it does work:
unpair [] = [] unpair ((x,y):xs) = x : unpair(xs) Any idea what I'm doing wrong?
unpairreturns a pair, not a list. Hence, both your examples are wrong. Usecase .. of (x,y) ->orlet (x,y)=... into access the components of a pair.