[Haskell-cafe] Correct parsers for bounded integral values
Pierre Thierry
pierre at nothos.net
Mon Jul 21 16:33:22 UTC 2025
Le 21/07/2025 à 17:42, Stefan Klinger a écrit :
> x = 123456
> is equivalent to
> x = fromInteger (read "123456" :: Integer)
It's basically what happens internally. You can see the convertInt
<https://hackage.haskell.org/package/ghc-internal-9.1201.0/docs/src/GHC.Internal.Read.html#convertInt>
function and it's used a few lines beneath in the Read Int instance.
convertInt :: Num a => L.Lexeme -> ReadPrec a
convertInt (L.Number n)
| Just i <- L.numberToInteger n = return (fromInteger i)
> But there is a *different* read function
>
> read :: String -> Word8
>
> which is not used in the scenario above, and this is the buggy one
> (and all its bounded cousins).
Well, IIUC, it conforms to the Haskell 98 specification. In that sense,
it's not buggy. But the specification may be sound and counter-intuitive
(which is not an uncommon combination…).
Curiously,
Pierre Thierry
--
pierre at nothos.net
0xD9D50D8A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20250721/a79347ea/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xC5ED7720D9D50D8A.asc
Type: application/pgp-keys
Size: 10496 bytes
Desc: OpenPGP public key
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20250721/a79347ea/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20250721/a79347ea/attachment.sig>
More information about the Haskell-Cafe
mailing list