Haskell List of tuples to list?

Your question is not very certain about how the tuples should be converted into a list. I assume that you want to have them flattend - for instance (1,2),(3,4) should become 1,2,3,4.

Your question is not very certain about how the tuples should be converted into a list. I assume that you want to have them flattend - for instance, (1,2),(3,4) should become 1,2,3,4. This translation is only possible, if the two elements of your tuple are of the same type, than you can do something like this: tupleToList :: (a,a) -> a tupleToList ((a,b):xs) = a : be : tupleToList xs tupleToList _ = In the general case, such a translation is impossible.

One thing I could imagine to make the impossible possible is to use Either to wrap up the two different types: tupleToList :: (a,b) -> Either a be tupleToList ((a,b):xs) = Left a : Right be : tupleToList xs.

1 or (>>= \(a,b) -> Left a,Right b) – sdcvvc Jun 7 '11 at 21:48.

You could also use a fold and avoid explicit recursion: tupleToList = foldr (\(f,s) a -> f : s : a) Or: tupleToList = foldl (\a (f,s) -> a ++ f,s) (For elements of the same type).

2 (x,y) : xs is of type (a,a) – Aymen Jun 7 '11 at 19:24.

Your question is not very certain about how the tuples should be converted into a list. I assume that you want to have them flattend - for instance (1,2),(3,4) should become 1,2,3,4 .

You could also use a fold and avoid explicit recursion.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions