[Haskell-cafe] Correct parsers for bounded integral values

Jeff Clites jclites at mac.com
Fri Aug 8 00:37:11 UTC 2025


Thanks Brandon for the info. I don't fully understand the implications of having the carry bit set on the resulting 128-bit value, but that's okay.

One thing I noticed about this:

> On Jul 20, 2025, at 5:50 PM, Brandon Allbery <allbery.b at gmail.com> wrote:
> 
> [...]
> That it otherwise behaves as modular is in support of this, not in support of a mathematical law, and the behavior might differ on other architectures (e.g. PPC, or if someone somewhere still has a processor using 1s- complement). Which is the most important point: the Report specifies `Integral` types other than `Integer` to behave like the machine type, and you're basically assuming x86-64 (_probably_ also AArch64 but i haven't studied that one, just assuming it's 2s-complement) if you assume either modular arithmetic or any other behavior. The only promise you get is "matches the underlying hardware".

Actually, this section of the Report:

    https://www.haskell.org/onlinereport/haskell2010/haskellch18.html#x26-22300018

says this:

    This module provides signed integer types of unspecified width (Int) and fixed widths (Int8, Int16, Int32 and Int64). All arithmetic is performed modulo 2^n, where n is the number of bits in the type.


So that seems to contract the idea that they are just meant to match the underlying hardware.

Jeff


More information about the Haskell-Cafe mailing list