nocturne
nocturne

Reputation: 647

List of strings to list of chars - [[Char]] to [Char] haskell

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.

Upvotes: 1

Views: 2377

Answers (2)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476709

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

Upvotes: 4

Chad Gilbert
Chad Gilbert

Reputation: 36375

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

Upvotes: 4

Related Questions