haskell - quickCheck (0 /= 0) ?!

Ezt a viselkedest nem igazan birom megfejteni


-------------------------------------------------------------------
-- | modular power. Is there a way in haskell to do the bittrick here?
modPow :: Int -> Int -> Int -> Int
modPow a b n
    | n < 2     = error $ "Not valid modulus " ++ show n
    | b < 0     = error $ "Negative exponent " ++ show b
    | b == 0    = 1
    | otherwise = a * modPow a (b - 1) n `mod` n


-------------------------------------------------------------------
propModPow a b n = n > 1 && b > 0 ==> a ^ b `mod` n == modPow a b n
    where types = (a :: Int, b :: Int, n :: Int)

Ezutan a teszt:


$ ghci modpow.hs
> Test.QuickCheck.quickCheck propModPow
*** Failed! Falsifiable (after 7 tests and 3 shrinks):    
6
12
3

Es itt jon amit nem ertek:


> modPow 6 12 3
0
> 6 ^ 12 `mod` 3
0

Hozzászólások


Prelude> 6 ^ 12 `mod` 3 :: Integer
0
Prelude> 6 ^ 12 `mod` 3 :: Int
2
Prelude> 6 ^ 12 `mod` 3
0