以下代码:
Module Main where
main :: IO ()
main = do putStrLn "hello"
putStrLn $ "2 exp 6 = " ++ show (2 `exp1` 6)
exp1 :: Integer -> Integer -> Integer
exp1 x n | n == 0 = 1
| n == 1 = x
| even n = exp1 (x*x) m
| odd n = x * exp1 (x*x) (m-1)
where m = n `div` 2
为4
生成输出2 `exp1` 6
,这显然是错误的。
感谢
答案 0 :(得分:6)
奇怪的情况是错误的。您最终将exp1 4 3
评估为4 * (exp1 16 0)
。