Monday 6 June 2016

Haskell: Process list of tuples

Sample input:
a = [("eo","th"),("or","he")]

Sample output:
[('e','t'),('o','h'),('o','h'),('r','e')]


ListUtil.hs
process :: [(String,String)] -> [(Char, Char)]
process [] = []
process ((first, second):xs) = (head first, head second) : (head (tail first), head(tail second)) : (process xs)

Prelude> :load ListUtil.hs
[1 of 1] Compiling Main             ( ListUtil.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> process [("eo","th"),("or","he")]
[('e','t'),('o','h'),('o','h'),('r','e')]
*Main> 



Previous                                                 Next                                                 Home

No comments:

Post a Comment