在 Richard Bird 的书“Introduction to Functional Programming Using Haskell”第二版中做练习。在以下代码的最后一行中,我收到错误:
"Parse error in pattern (n `times` Succ m)
请注意,在 的定义中接受了相同的模式(m 和 n 互换)times
。为什么我会收到此错误?
data Nat = Zero | Succ Nat
deriving (Eq, Ord, Show)
plus :: Nat -> Nat -> Nat
m `plus` Zero = m
m `plus` Succ n = Succ (m `plus` n)
m `times` Zero = Zero
m `times` Succ n = (m `times` n) `plus` m
divide :: Nat -> Nat -> Nat
Zero `divide` m = Zero
(n `times` Succ m) `divide` n = Succ m