Underscores not allowed in float and integer literals [GHC-62330]

The NumericUnderscores extension allows underscores to be included in float and integer literals for better legibility of long numbers and is enabled by default. If the NoNumericUnderscores extension is enabled or NumericUnderscores is not enabled in earlier GHC versions, the inclusion of underscores in float and integer literals causes this error.

Examples

Underscore not allowed in float literal

Float literals may not contain underscores if the NoNumericUnderscores language extension is enabled. Here, the float literal 1_000.0_1 contains underscores, but the extension is enabled. The error can be fixed by removing the underscores or disabling the extension.

Error Message

UnderscoreInFloatLiteral.hs:6:3: error: [GHC-62330]
    Illegal underscores in floating literals
    Suggested fix: Perhaps you intended to use NumericUnderscores
  |
6 | f 1_000.0_1 = ()
  |   ^^^^^^^^^
UnderscoreInFloatLiteral.hs
Before
{-# LANGUAGE NoNumericUnderscores #-}

module UnderscoreInFloatLiteral where

f :: Float -> ()
f 1_000.0_1 = ()
f _   = ()
After
{-# LANGUAGE NoNumericUnderscores #-}

module UnderscoreInFloatLiteral where

f :: Float -> ()
f 1000.01 = ()
f _   = ()
Underscore not allowed in integer literal

Integer literals may not contain underscores if the NoNumericUnderscores language extension is enabled. Here, the integer literal 1_000 contains underscores, but the extension is enabled. The error can be fixed by removing the underscores or disabling the extension.

Error Message

UnderscoreInIntegerLiteral.hs:6:3: error: [GHC-62330]
    Illegal underscores in integer literals
    Suggested fix: Perhaps you intended to use NumericUnderscores
  |
6 | f 1_000 = ()
  |   ^^^^^
UnderscoreInIntegerLiteral.hs
Before
{-# LANGUAGE NoNumericUnderscores #-}

module UnderscoreInIntegerLiteral where

f :: Int -> ()
f 1_000 = ()
f _   = ()
After
module UnderscoreInIntegerLiteral where

f :: Int -> ()
f 1_000 = ()
f _   = ()