Hi all so I have this homework assignment in Haskell where we have to work with the Nat Data type which only gives Zero and Succ(n) for one. So one is Succ(Zero), two is Succ(Succ(Zero)) and so on. We are also supposed to add subtract multiply these data types recursively.
One of the problems look like this
--Add two natural numbers.
--
-- `>>> add one two`
-- Succ (Succ (Succ Zero))
--
-- `>>> add Zero one == one`
-- True
--
-- `>>> add two two == four`
-- True
--
-- `>>> add two three == add three two`
-- True
--
My problem is when I am doing recursion I have a base case, but as I call it it just returns the base case and doesn't particularly bubble back up.
Any help or explanation on how to recursion in Haskell with pattern matching would be appreciated
EDIT: The code I have is
add :: Nat -> Nat -> Nat
add Zero Zero = Zero
add Zero (Succ i) = Succ(pred i)
add (Succ i) Zero = Succ(pred i)
add (Succ i) (Succ j) = Succ(add i j)
Where pred is another function
pred :: Nat -> Nat
pred Zero = Zero
pred (Succ Zero) = Zero
pred (Succ i) = Succ(pred i)