0

I need to write a function which takes a list and returns a concatenated string consisting of all strings from the input list, separated with spaces '', e.g.

setTogether ["aaa", "bbb", "c", "cc"] == "aaa bbb c cc"

setTogether ["aaa"] == "aaa"

with the type signature: setTogether :: [String] -> String

setTogether :: [String] -> String
setTogether ls = [x | x <- ls]

^as you can see I'm kind of lost! Any help is greatly appreciated :)

Edit: I'm not supposed to use "words" or "unwords"

Markiy99
  • 83
  • 7
  • 2
    `[x | x <- ls]` is simply the same as `ls`. – Willem Van Onsem Sep 14 '20 at 17:08
  • 4
    Does this answer your question? [Is there any haskell function to concatenate list with separator?](https://stackoverflow.com/questions/9220986/is-there-any-haskell-function-to-concatenate-list-with-separator) – Ari Fordsham Sep 14 '20 at 17:10
  • 1
    Do you just need a function that does this (in which case, it's a duplicate of the question Silver Rampart linked to), or are you required to *write* the function yourself as an assignment? – chepner Sep 14 '20 at 17:20
  • Probably should've mentioned that! I need to write the function; I'm not allowed to use words/unwords @chepner – Markiy99 Sep 14 '20 at 17:22
  • 1
    Even if you need to write the function (which is `intercalate " "`) there are a bunch of examples of `intercalate` from scratch in anwsers to the question that Silver Rampart linked – Joe Sep 14 '20 at 17:28

1 Answers1

2
setTogether :: [String] -> String
setTogether ss = intercalate " " ss

This worked for me :)

Markiy99
  • 83
  • 7