Saturday 4 June 2016

Haskell: Write a function to concatenate elements of list of lists.

For example, it should return "abcde" for ["abc","de"].


ListUtil.hs
concatLists :: [[Char]] -> [Char]
concatLists [] = ""
concatLists (x:xs) = x ++ (concatLists xs)

*Main> :load ListUtil.hs
[1 of 1] Compiling Main             ( ListUtil.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> concatLists ["abc", "de"]
"abcde"
*Main> concatLists ["abc", "de", "fgh"]
"abcdefgh"
*Main>



Previous                                                 Next                                                 Home

No comments:

Post a Comment