Anthony Riccelli
Anthony Riccelli

Reputation: 1

How to print each lists values in Haskell

I have a list of lists like [[a,c,e],[b,d,f]] and I was wondering how to print out every value from the lists, one at a time from each list.

The order I want when I print is abcdef.

I've been thinking about this for a while but I can't seem to figure it out.

Upvotes: 0

Views: 125

Answers (2)

Ori
Ori

Reputation: 154

How's the following

concat $ transpose [[1,2,3],[4,5,6]]

returns

[1,4,2,5,3,6]

mapM_ (putStr . show) [1,4,3,5,3,6]

Upvotes: 1

Andrew
Andrew

Reputation: 1492

combine :: [a] -> [a] -> [a]
combine [] ys = ys
combine (x:xs) ys = x:combine ys xs

main :: IO ()
main = do
    print (combine [1,3,5] [2,4,6])
    return ()

outputs: [1,2,3,4,5,6]

Upvotes: 0

Related Questions