[Haskell-cafe] Confused by ghci output

Kevin Charter kcharter at gmail.com
Thu May 31 18:52:22 CEST 2012


Hi Clark,

On Thu, May 31, 2012 at 10:35 AM, Clark Gaebel <cgaebel at uwaterloo.ca> wrote:

> *X> 3^40 `mod` 3 == modexp2 3 40 3
> False
> *X> modexp2 3 40 3
> 0
> *X> 3^40 `mod` 3
> 0
>
> I'm confused. Last I checked, 0 == 0.
>

Your HPaste shows the type of modexp2 is Int -> Int -> Int -> Int, so ghci
will infer that (3^40) is an Int. But an Int isn't big enough to hold 3^40.

Prelude> 3^40 :: Int
-6289078614652622815
Prelude> (3^40 :: Int) `mod` 3
2

Kevin
-- 
Kevin Charter
kevin.charter at acm.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120531/5a5bd8c6/attachment.htm>


More information about the Haskell-Cafe mailing list