I am trying to understand recursion in Haskell. I want to write a simple recursive function with the following properties: if x > 50 then rec(x) = x - 5 and rec(x) = rec(rec(x+10)) otherwise.
This is what I came up with:
rec x = if x > 50
then x-5
else rec (rec (x+10))
The not recursive part seems to work fine, but the recursion doesn't. Every number less than 50 just return 50. For example rec 60 = 55 rec 40 = 50 rec 25 = 50
Any suggestions on how to fix my code would be appreciated.
rec x | x > 50 = x - 5) and then I would suggest you also explain what you expect the function to return, because to me it seems working correctly.