You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
After debugging a runtime error (shocking!) in my application, I found that guards may cause stack overflows when used in conjunction with a recursive call due to the non-lazy nature of Elm. (Coming from the Haskell world, this was totally shocking and completely unexpected for me!)
To provide a simple repro case, here is a snippet using elm-guards
foo:Int->Intfoo x = x <=0=> x
|= foo (x -1)
but this will stack overflow because the foo (x - 1) is attempted to be evaluated even when the conditions are met to return from the first branch. In comparison, the following code, using if (...) then (...) else (...) constructs instead, does not try evaluating branches it does not need:
foo_:Int->Intfoo_ x =if x <=0then
x
else
foo_ (x -1)
and foo_ 5 will evaluate to 0 as expected.
Are there plans to make this library usable with recursion? If not, can we at least get a warning in the README?
Thank you for the library and for your help!
The text was updated successfully, but these errors were encountered:
Hello,
After debugging a runtime error (shocking!) in my application, I found that guards may cause stack overflows when used in conjunction with a recursive call due to the non-lazy nature of Elm. (Coming from the Haskell world, this was totally shocking and completely unexpected for me!)
To provide a simple repro case, here is a snippet using
elm-guards
but this will stack overflow because the
foo (x - 1)
is attempted to be evaluated even when the conditions are met to return from the first branch. In comparison, the following code, usingif (...) then (...) else (...)
constructs instead, does not try evaluating branches it does not need:and
foo_ 5
will evaluate to0
as expected.Are there plans to make this library usable with recursion? If not, can we at least get a warning in the README?
Thank you for the library and for your help!
The text was updated successfully, but these errors were encountered: