Numeric underscores

When we write long numbers, we usually group the digits for easier reading: For example, we would write one million as “1,000,000” rather than “1000000”.Grouping styles vary by region and language. Groups of three digits separated by commas is the American convention.

Unfortunately, the standard Haskell language does not allow us to write numbers with any sort of visual grouping of the digits:

It may be difficult to judge at a glance whether the number we’ve written in the above example is actually one million; we have to carefully count the number of zeros.

The NumericUnderscores extension provides a remedy for this problem.

With the extension enabled, you may insert an underscore at your discretion anywhere within a numeric literal. The compiler ignores the underscores; they are only there to assist human readers.

Type Classes offers courses and projects to get you started and make you an expert in FP with Haskell. For $29/month, you get access to the complete archive and all the latest content.