Skip to content

Strings

In Gren, strings are zero or more characters contained within double quotes:

name : String
name =
"Laura"
empty : String
empty =
""

Character literals are exactly one character contained within single quotes:

key : Char
key =
'a'

Multi-line strings can be contained within three double quotes. Leading whitespace will be removed from the resulting string, but newlines will be preserved:

story : String
story =
"""
Once upon a time,
there was a long string.
It was alright.
"""

To include a double quote inside a string, it must be escaped with \:

name : String
name =
"Dwayne \"The Rock\" Johnson."

A single quote character literal can also be escaped:

singleQuote : Char
singleQuote =
'\''

And you can escape the \ itself with a preceding \:

backslash : Char
backslash =
'\\'
path : String
path =
"c:\\my\\file"

You do not need to escape double quotes from multiline strings:

"""
I was like "Whoa"
and they were like "Yeah"
"""

You can combine two strings into one with ++:

greet : String -> String
greet name =
"Hello, " ++ name

To see what else you can do with strings, check the String module documentation.