Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack overflow in your solution for McCarthy91 problem #1

Closed
m1nhtu99-hoan9 opened this issue Mar 18, 2020 · 5 comments
Closed

stack overflow in your solution for McCarthy91 problem #1

m1nhtu99-hoan9 opened this issue Mar 18, 2020 · 5 comments

Comments

@m1nhtu99-hoan9
Copy link

stack overflow in your solution for McCarthy91 problem

@BoeingX
Copy link
Owner

BoeingX commented Mar 19, 2020

stack overflow in your solution for McCarthy91 problem

Could you please provide some context for the issue you have? There is a unit test for the solution and it passes without problem.

@m1nhtu99-hoan9
Copy link
Author

Here is my code snippet that I refer from your one:

module McCarthy91 where
  mc91 :: Integer -> Integer
  mc91 n
    | n > 100   = n - 10
    | otherwise = mc91 (mc91 (n + 1))

I try that code in GHCi as follow:

*Main> :load recursion-exercises/mc-carthy-91.hs
[1 of 1] Compiling McCarthy91       ( recursion-exercises/mc-carthy-91.hs, interpreted )
Ok, modules loaded: McCarthy91.
*McCarthy91> map mc91 [95..110]
[*** Exception: stack overflow

So, because your test passed successfully, is this a GHCi-related problem?

@BoeingX
Copy link
Owner

BoeingX commented Mar 20, 2020

I think you got a typo in your definition, it should be otherwise = mc91 (mc91 (n + 11)) instead of otherwise = mc91 (mc91 (n + 1))

@m1nhtu99-hoan9
Copy link
Author

OMG sorry for bothering you for such a silly mistake. Thank you very much for your time!

@BoeingX
Copy link
Owner

BoeingX commented Mar 20, 2020

Sure, no problem :)

@BoeingX BoeingX closed this as completed Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants