I am trying to solve a problem from book purescript by example
Write a recursive function countEven
which counts the number of even integers in an array
Here’s my code below
Code
isEvenInt :: Int -> Int
isEvenInt a =
if a `mod` 2 == 0
then 1
else 0
countEven :: forall a. Array a -> Int
countEven ar =
if null ar
then 0
else isEvenInt (fromMaybe 0 (head ar)) + (countEven $ fromMaybe [] $ tail ar )
It’s giving some errors and I am not able to figure out what to do
Error
Error found:
in module Test.MySolutions
at test/MySolutions.purs:26:40 - 26:47 (line 26, column 40 - line 26, column 47)
Could not match type
a1
with type
Int
while trying to match type Maybe t0
with type Maybe Int
while checking that expression head ar
has type Maybe Int
in binding group countEven
where a1 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
t0 is an unknown type
if someone could tell what’s wrong with my code and what is error is all about?