How to delete second element from pairs in haskell?

Viewed 52

I am trying to get:

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

My attemp:

fun2 :: [(Int,Int)] -> [Int]
fun2 [] = []
fun2 ((a,b):ts) = **drop b**:fun2 ts  --have problem here 
1 Answers

You can map with fst :: (a, b) -> a:

fun2 :: [(a, b)] -> [a]
fun2 = map fst

or use pattern matching, like you already did:

fun2 :: [(a, b)] -> [a]
fun2 [] = []
fun2 ((a, _):ts) = a : fun2 ts
Related