In Haskell String is an alias for [Char]:

type String = [Char]

If you just want a function that converts a single char to a string you could e.g. do

charToString :: Char -> String
charToString c = [c]

If you prefer pointfree style you could also write

charToString :: Char -> String
charToString = (:[])
Answer from Thies Heidecke on Stack Overflow
🌐
Reddit
reddit.com › r/haskell › how to concatenate a character to a string
How to concatenate a character to a string : r/haskell
January 30, 2023 - Remember String is just a type alias for [Char]. You cant concatenate a Char to a [Char]. But you can concatenate a List with a single Char with another list of Char ( [head s1] ++ s2 ), or even prepend the single Char to a list of Char ( head s1 : s2 )
Discussions

How to combine the letters in two strings in haskell - Stack Overflow
I am learning Haskell and following the guide on http://learnyouahaskell.com/starting-out. I am at the point where it is shown: ghci> let nouns = ["hobo","frog","pope"] ghci> let adjective... More on stackoverflow.com
🌐 stackoverflow.com
haskell - How do I add a char to every item in a list? - Stack Overflow
As an exercise to see if I understand the map function I wanted to add a char 'a' to every item in the range A-Z. Well appearently I dont because I get these exceptions which I dont undestand as o... More on stackoverflow.com
🌐 stackoverflow.com
December 24, 2017
How to simplify string concatenation in Haskell? - Stack Overflow
I have this function: myF :: String -> String myF arg1 = "const" ++ arg1 Is there any way to simplify it? I think it might have to do with the operator "." but I can't figure out how to apply i... More on stackoverflow.com
🌐 stackoverflow.com
How to combine two strings i Haskell and return a new string - Stack Overflow
How to concatinate two strings . For example I have two lists ["me","you","he"] and ["she","they","it"]. I want to form a new list in which every correspondging strings are combined togatheer, lik... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › CMCDragonkai › f2dad871750b37c9f800
Haskell: Difference Lists Used for Concatenating Strings Efficiently · GitHub
Save CMCDragonkai/f2dad871750b37c9f800 to your computer and use it in GitHub Desktop. ... This makes the ++ operator right associative. Meaning operationally it evaluated like: ... This is a good thing, because since strings are linked lists, when appending, it is a linear operation O(n).
🌐
Blogger
haskelle.blogspot.com › 2013 › 03 › haskell-strings-and-characters.html
HASKELL: HASKELL STRINGS AND CHARACTERS
March 11, 2013 - The name String is often used instead ... for [Char] list of characters. An empty String is written "", and is a synonym for []. Regular list operators can be used to construct new strings. Prelude> 'H' : "askell" ... Haskell's name for the “append” function is ...
🌐
Hackage
hackage.haskell.org › package › base-4.3.1.0 › docs › Data-Char.html
Data.Char - Hackage - Haskell.org
Convert a character to a string using only printable characters, using Haskell source-language escape conventions.
Top answer
1 of 2
12

++ works only for lists, but x and y are only Char. After all, they're elements from a String (= [Char]), whereas the LYAH example had lists of lists of Char: [String] = [[Char]]:

-- [a] -> [a] -> [a]
-- vv     vv
[y ++ ' ' ++ y | x <- "abd", y <- "bcd"]
--           ^   ^           ^
--           Char           Char

-- vs

--                                        [String]          [String]
--                                       vvvvvvvvvv          vvvvv
[adjective ++ " " ++ noun | adjective <- adjectives, noun <- nouns]  
-- ^^^^^^^           ^^^^
-- String           String

Instead, use (:) to cons the characters on each other and onto the empty list:

[x : ' ' : y : [] | x <- "abd", y <- "bcd"]
2 of 2
8
x ++ ' ' ++ y

The actual problem here is, you are trying to concatenate three characters, with a function defined only for list of items. ++ will actually concatenate two lists, not two individual items and give a list.

  1. So, you can fix your program either by converting all the characters to strings, like this

    > [[x] ++ " " ++ [y] | x <- "ab", y <- "cd"]
    ["a c","a d","b c","b d"]
    

    Note the " ", not ' '. Because " " means a string with just a space character, but ' ' means just the space character.

  2. Or, convert y to a String, use cons operator with the ' ', and concatenate it to x converted to a string, like this

    > [[x] ++ (' ' : [y]) | x <- "ab", y <- "cd"]
    ["a c","a d","b c","b d"]
    
  3. Or, even simpler and intutive, as suggested by chi, create a list of characters, like this

    > [[x, ' ', y] | x <- "ab", y <- "cd"]
    ["a c","a d","b c","b d"]
    

Note: Wrapping a character with [] makes it a list of characters with just one character in it. It basically becomes a String.

🌐
Hackage
hackage.haskell.org › package › nri-prelude › docs › Text.html
Text
Convert a list of characters into a Text. Can be useful if you want to create a string primarily by consing, perhaps for decoding something.
🌐
Wordpress
tehgeekmeister.wordpress.com › 2008 › 12 › 22 › fast-string-appendingconcatenation-in-haskell
fast string appending/concatenation in haskell | tehgeekmeister's blog
December 23, 2008 - working on my graded reader project yesterday, i was really frustrated by how slow it was going. after profiling, i realized i was spending over 95% of my time appending strings; uh oh. i did something stupid. the code in question was something like this: appendToContent str page = page {pageContent = newContent} where newContent…
Find elsewhere
🌐
Hackage
hackage.haskell.org › package › text › docs › Data-Text.html
Data.Text - Hackage - Haskell.org
The resulting strings do not contain newlines. lines does not treat '\r' (CR, carriage return) as a newline character. ... O(n) Breaks a Text up into a list of words, delimited by Chars representing white space. ... O(n) Joins lines, after appending a terminating newline to each.
🌐
SourceForge
pleac.sourceforge.net › pleac_haskell › strings.html
Strings
Strings · PLEAC-Haskell · 1. Strings · Introduction · str = "\\n" -- two characters, \ and an n str2 = "Jon 'Maddog' Orwant" -- in haskell we can do string only with ", no single quote str3 = "\n" -- a "newline" character str4 = "Jon \"Maddog\" Orwant" -- literal double quotes str5 = "Multiline ...
🌐
Programming Idioms
programming-idioms.org › idiom › 289 › concatenate-two-strings › 5381 › haskell
Concatenate two strings, in Haskell
Do you know the best way to do this in your language ? New implementation... ... StringBuilder t = new StringBuilder(a); Formatter f = new Formatter(t); f.format("%s", b).flush(); String s = t.toString();
🌐
Hackage
hackage.haskell.org › package › strings-1.1 › docs › Data-Strings.html
Data.Strings - Hackage - Haskell
Appends the given character n times to both sides, such that the resulting string has the given length. ... Create a string from a Haskell String.
🌐
HaskellWiki
wiki.haskell.org › Cookbook › Lists_and_strings
Cookbook/Lists and strings - Haskell « HaskellWiki
June 1, 2019 - In Haskell, lists are what Arrays are in most other languages. The list of all squares can also be written in a more comprehensive way, using list comprehensions: ... Since strings are lists of characters, you can use any available list function.
🌐
HackerNoon
hackernoon.com › untangling-haskells-strings-d47d2170cc4
Untangling Haskell’s Strings | HackerNoon
May 15, 2017 - Haskell is not without its faults. One of the most universally acknowledged annoyances, even for pros, is keeping track of the different string types. There are, in total, five different types representing strings in Haskell. Remember Haskell is strongly typed.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › programming languages tutorial › haskell string
Haskell String | How String Type Works in Haskell | Examples
May 31, 2023 - This function also used to break the string but at the newline character. Here if we use ‘\n’ then it will break the string from there and create an array containing the result of the string. This function also return us the array as result. ... This function does opposite of lines function in Haskell, it will join the string and return us the string object. Return type for this function is string value after joining. Also it will append ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
ZVON
zvon.org › other › haskell › Outputprelude › String_d.html
Haskell : String
Enjoy! ZVON team Any suggestions send to webmaster@zvon.org, please
🌐
Lotz84
lotz84.github.io › haskellbyexample › ex › string-functions
Haskell by Example: String Functions
import Data.List import Data.Char include :: String -> String -> Bool include xs ys = or . map (isPrefixOf ys) . tails $ xs joinWith :: [String] -> String -> String joinWith xs sep = concat . init . concat $ [[x, sep] | x <- xs] split :: String -> Char -> [String] split "" _ = [] split xs c = let (ys, zs) = break (== c) xs in if null zs then [ys] else ys : split (tail zs) c main = do putStrLn $ "Contains: " ++ show ("test" `include` "es") putStrLn $ "Count: " ++ show (length . filter (=='t') $ "test") putStrLn $ "HasPrefix: " ++ show (isPrefixOf "te" "test") putStrLn $ "HasSuffix: " ++ show (i