Hello stackoverflow community,
I have a rather simple piece of code that is getting a strange error. Here is my code:
multiplyByTwo 0 = 1
myltiplyByTwo x = 2 * multiplyByTwo (x-1)
as you can see, it is simple recursion. I am getting the “Non-exhaustive pattern in function
multiplyByTwo” exception. I do not understand why I am getting this, as I have already set the lowest value multiplyByTwo 0 = 1 therefore I would guess that the function is not calling itself after that point. What I am saying is that I do not understand why this pattern is “non-exhaustive”. I am assuming that the number you enter for x is positive.
thank you for any help you can give.
You have a typo in the second line:
thus that defines a new function, and
multiplyByTwois only defined for the argument 0.