Empty single quotes [GHC-11861]

Language extension: TemplateHaskell

Single quotes are used for character and literals including “new line” ('\n'), “carriage return” ('\r'), “horizontal tab” ('\t'), and “vertical tab” ('\v'). The complete list of character escapes is described in the Haskell Report section 2.6, Character and String Literals. Character literals cannot be empty.

Another usage of single quotes is in TemplateHaskell; please refer to the GHC documentation for details.

Example error text

 error: [GHC-11861]
    Parser error on `''`
    Character literals may not be empty

Examples

Empty character literals

An empty pair of single quotes is not a valid literal. To indicate a whitespace character, either use an explicit space character ' ' or an escape code such as '\n' for a newline.

Example error text

 error: [GHC-11861]
    Parser error on `''`
    Character literals may not be empty
  |
4 |   where foo = ''
  |               ^^
Example.hs
Before
module Example where

example = foo
  where foo = ''
After
module Example where

example = foo
  where foo = ' '
Incorrect TemplateHaskell syntax using ''

An empty pair of single quotes is not a Haskell character literal.

When Template Haskell is enabled, ''T is syntax that refers to a quoted name of the type T. In this case, '' is not an empty character literal, but rather part of the quotation syntax for type names. Read more at TemplateHaskellQuotes.

In this context, GHC chooses to interpret '' as an empty character literal rather than as an incomplete quoted type name, which results in this message.

Example error text

error: [GHC-11861]
    Parser error on `''`
    Character literals may not be empty
    Suggested fix:
      Perhaps you intended to use quotation syntax of TemplateHaskell,
      but the type variable or constructor is missing
  |
6 |   where foo = ''
  |               ^^
Example.hs
Before
{-# LANGUAGE TemplateHaskell #-}

module Example where

example = foo
  where foo = ''
After
{-# LANGUAGE TemplateHaskell #-}

module Example where

example = foo
  where foo = ''Int