J maria
J maria

Reputation: 373

How to delete second element from pairs in haskell?

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 

Upvotes: 3

Views: 55

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477676

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

Upvotes: 2

Related Questions