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"

5
  • 2
    [x | x <- ls] is simply the same as ls. Commented Sep 14, 2020 at 17:08
  • 4
    Does this answer your question? Is there any haskell function to concatenate list with separator? Commented Sep 14, 2020 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? Commented Sep 14, 2020 at 17:20
  • Probably should've mentioned that! I need to write the function; I'm not allowed to use words/unwords @chepner Commented Sep 14, 2020 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 Commented Sep 14, 2020 at 17:28

1 Answer 1

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

This worked for me :)

Sign up to request clarification or add additional context in comments.

2 Comments

Your question doesn't mention needing [ and ] in the answer. For that, setTogether = intercalate " " would be sufficient.
Oh, true! Thanks :) Editing answer now @chepner

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.