So I have this exercise with the following data type
data Nat = Zero | Succ Nat deriving (Eq,Ord,Show,Read)
This can be used to represent a natural number, for example 2 = Succ (Succ Zero). I implemented a function that checks if the number is even.
even :: Nat -> Bool
even x = count x `mod` 2 == 0
count :: Nat -> Int
count Zero = 0
count (Succ x) = 1 + count x
It works fine for Zero, but whenever I try for something different, such as count Succ Zero or count Succ (Succ Zero)
*Main> even Succ Zero
<interactive>:6:1: error:
* Couldn't match expected type `Nat -> t' with actual type `Bool'
* The function `evenN' is applied to two arguments,
but its type `Nat -> Bool' has only one
In the expression: evenN Succ Zero
In an equation for `it': it = evenN Succ Zero
* Relevant bindings include it :: t (bound at <interactive>:6:1)
<interactive>:6:7: error:
* Couldn't match expected type `Nat' with actual type `Nat -> Nat'
* Probable cause: `Succ' is applied to too few arguments
In the first argument of `evenN', namely `Succ'
In the expression: evenN Succ Zero
In an equation for `it': it = evenN Succ Zero
even (Succ Zero)- Jorge AdrianoInt. Hint: write mutually recursiveevenandoddfunctions. - dfeuerNatis going to be a data type that you are going to stick with for a whiile then i guess you best write anEnuminstance first. - Redu