Jump to content

haskell: lists of tuples to list

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
kunti

kunti

    Newbie

  • Members
  • Pip
  • 3 posts
Hi guys,

I am having difficulties on how to write a function that will take a list of tuples and convert it to a list, example:

[(1,2), (3,4)] => [1,2,3,4]

can you please tell me how to do it?

One other thing, is there any way to write a function zipWith which is non-recursive, if there is how?

#2
a-z-z

a-z-z

    Newbie

  • Members
  • PipPip
  • 11 posts
Hey,

the two functions you requires are:

t2l :: (Int, Int) -> [Int]
t2l (a,b) = [a,b]

t2l2 :: [(Int, Int)] -> [Int]
t2l2 array = concat (map t2l array)

then you get this:

Cw2008> t2l2 [(1,2), (3,4)]
[1,2,3,4]

excuse the 'Cw2008>', I did it in my coursework file :)

a-z-z