Strings

A string is a sequence of zero or more characters, used to represent some kind of text or message. In fact, a string is really just a list of characters, that is, a value of type List(Char).

A string can be written using the usual syntax for a list of characters, that is,

mystr : List(Char)
mystr = ['h', 'e', 'l', 'l', 'o']

However, this is tedious, so Disco also provides special syntax for strings using double quote marks:

mystr2 : List(Char)
mystr2 = "hello"

In fact, these are exactly the same; the only difference is that mystr2 uses more convenient syntax:

Disco> mystr == mystr2
true

A string can be empty; the empty string is written "". Note that strings can also contain escape sequences. For example, "don\'t \"go\"\naway".

Note the difference between 'x' and "x":

  • 'x' is a single character, i.e. a value of type Char.
  • "x" is a string, i.e. a value of type List(Char), which just happens to have only a single character.