<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Le 21/07/2025 à 17:42, Stefan Klinger a
écrit :<span style="white-space: pre-wrap">
</span></div>
<blockquote type="cite" cite="mid:aH5f-Etb3LhqgDd7@tauhou">
<pre wrap="" class="moz-quote-pre"> x = 123456
is equivalent to
x = fromInteger (read "123456" :: Integer)</pre>
</blockquote>
<p>It's basically what happens internally. You can see the <a
href="https://hackage.haskell.org/package/ghc-internal-9.1201.0/docs/src/GHC.Internal.Read.html#convertInt"><font
face="monospace" size="4">convertInt</font></a> function and
it's used a few lines beneath in the <font face="monospace"
size="4">Read Int</font> instance.</p>
<pre>convertInt :: Num a => L.Lexeme -> ReadPrec a
convertInt (L.Number n)
| Just i <- L.numberToInteger n = return (fromInteger i)</pre>
<blockquote type="cite" cite="mid:aH5f-Etb3LhqgDd7@tauhou">
<pre wrap="" class="moz-quote-pre">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).</pre>
</blockquote>
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…).
<p>Curiously,<br>
Pierre Thierry<br>
-- <br>
</p>
<div class="moz-signature">
<pre><a href="mailto:pierre@nothos.net"
class="moz-txt-link-freetext">pierre@nothos.net</a>
0xD9D50D8A</pre>
</div>
</body>
</html>