1

I need to convert list like this ["a","b","c"] to this ['a','b','c']. The thing is i used

splitOn

function which gave me [[Char]] from [Char]. Is there a way to convert this list of string to list of char? Assuming strings are length of 1 of course.

5
  • What do you want to do if any of the strings aren't length 1? Commented Feb 27, 2018 at 15:08
  • It will not happen, because of my exact input to splitOn Commented Feb 27, 2018 at 15:14
  • 2
    You might also want to use hoogle for those kind of questions. Given signatures it usually spits out some useful pointers. Commented Feb 27, 2018 at 18:52
  • I tried it, only thing with this signatures found was unlines and unwords. Which does not work for me. But thanks for your point. Commented Feb 27, 2018 at 18:54
  • 1
    @nocturne concat is the fourth result Commented Feb 28, 2018 at 5:37

2 Answers 2

4

Yes, you can use concat :: [[a]] -> [a]:

Prelude> concat ["a","b","c"]
"abc"

Since a String is a type alias for [Char], so "abc" is short for ['a', 'b', 'c']:

Prelude> concat ["a","b","c"] == ['a', 'b', 'c']
True
Sign up to request clarification or add additional context in comments.

1 Comment

It worked thanks! I will mark this as right answer later.
4

concat ["a", "b", "c"] will give you the string "abc" which is the same as ['a', 'b', 'c']

Comments

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.