
Hi, This is a function that returns true if divisible by 2. But it keeps telling me parse error on input | . What is wrong here. is_even n | mod n 2 == 0 | True Not sure if I need another statement for false John

Hi, the "| True" part is wrong. It should read: is_even n | n `mod` 2 == 0 = True | otherwise = False. Kind regards Chris
Hi, This is a function that returns true if divisible by 2. But it keeps telling me parse error on input | . What is wrong here. is_even n | mod n 2 == 0 | True Not sure if I need another statement for false John
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sun, Oct 04, 2009 at 04:11:35PM +0200, informationen wrote:
the "| True" part is wrong. It should read:
is_even n | n `mod` 2 == 0 = True | otherwise = False.
Which means that is_even may be expressed as is_even n = n `mod` 2 == 0 Equivalently, in C the first code would be int is_even(int n) { if (n % 2 == 0) return 1; else return 0; } while the code I presented above would be int is_even(int n) { return (n % 2 == 0); } HTH, -- Felipe.
participants (3)
-
Felipe Lessa
-
informationen
-
John Moore