3

Is there an easy way to change [Int] -> String ? My output function returns a list of int but the format should be a string as in the example below

example: [1,2,3,4] -> 1 2 3 4

3
  • 1
    Possible duplicate of Haskell int list to String Commented Mar 4, 2016 at 10:04
  • @PRVS That one does more work, also involving non-base-10 representations. Commented Mar 4, 2016 at 10:09
  • What do you mean with change? Commented Mar 4, 2016 at 10:14

1 Answer 1

7

To turn an integer into a string, use show.

To turn a list of integers into a list of strings, use map show.

To add " " between every string in a list of strings, use intersperse " ". (Requires import Data.List)

To concatenate a list of strings, use concat.

Alternative: try unwords ["a","b","c"] in GHCi.

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

1 Comment

Thanks, that's exactly what I needed. I was unsure what to do after map show, but you made it clear enough. Thumbs up!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.