The OverloadedStrings extension

Contents
  • What “overloaded” means
  • How it works
  • Alternatives to String
  • Unusual instances
    • ByteString
    • Aeson
    • Cabal
  • Hazard: Type ambiguity
Video
  • 13 minutes
Tags
String Text IsString

OverloadedStrings is one of the most commonly-enabled GHC extensions.

In normal Haskell without OverloadedStrings, string literals (anything enclosed in double quotes, like "hello") always have the type String, which is a type alias for [Char] defined in the base package. So "hello" can also be written slightly more explicitly (although less conveniently) as the list of characters 'h':'e':'l':'l':'o':[].

The OverloadedStrings extension makes string literal syntax more general, allowing string literals to denote values of types other than String.

There are some of the pitfalls of string overloading: It has the potential to introduce type ambiguity, and there is no good way to handle the case where the conversion from String may fail. In some cases you may want to consider using QuasiQuotes, a more powerful but more cumbersome tool, instead.