Search code examples
stringlisthaskellconcatenation

Haskell convert list of list of strings to string


I'm currently trying to pretty-print a list of list of strings as a single string. My current code is

pretty :: [[String]]->String
pretty x
   = concat(concat(x))

main :: IO ()
main
  = putStrLn (show (pretty [["hi","hi","hi"]]))

When asked to do pretty [["hi","hi","hi"]], it converts it to "hihihi" but when asked pretty [["hi","hi","hi"]["hi","hi","hi"]] the compiler gives the following error

main.hs:7:29: error:
* Couldn't match expected type `[[Char]] -> [String]'
              with actual type `[[Char]]'
* The function `["hi", "hi", "hi"]' is applied to one argument,
  but its type `[[Char]]' has none
  In the expression: ["hi", "hi", "hi"] ["hi", "hi", "hi"]
  In the first argument of `pretty', namely
    `[["hi", "hi", "hi"] ["hi", "hi", ....]]'
 |
  7 |   = putStrLn (show (pretty [["hi","hi","hi"]["hi","hi","hi"]]))
 |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Solution

  • Never mind guys. It turned out I forgot the comma in [["hi","hi","hi"],["hi","hi","hi"]]