Boolean Operator Short Circuiting #183
Replies: 2 comments 9 replies
-
I haven't thought of it very, very deeply, but I find it intriguing, the concept of adding perhaps Doing such would allow us to encode the concept of infix ops to natively support math and boolean operators. We could also potentially add associativity as well. I think the concepts of infix, postfix, prefix for Ops and associativity make this worth at least discussing. It would also allow us to encode consistent semantics in the IR. |
Beta Was this translation helpful? Give feedback.
-
Way back when this was originally implemented it did do short circuiting: Since then we decided that it doesn't worth the additional complexity to do that since it has minimal performance impact. You are right that there is a behavior difference when one of the arguments contains infinite recursion, but we consider those to be invalid and we don't concern ourselves with the behavior around that. Generally we take the approach of assuming that an IR is valid if the computations don't fail and complete in bounded time. We may not be able to reject all invalid IRs at compile time right now, but assuming that the IR is valid allows us (and all tool developers) to avoid a lot of complexity. So your IR may still be invalid if it goes through |
Beta Was this translation helpful? Give feedback.
-
Elm supports boolean operator circuiting - i.e., in
True || <expr>
orFalse && <expr>
,<expr>
will not be evaluated. This is significant in cases where<expr>
would not return.As far as I can tell, the current elm-based interpreter does not support this. From the following code, shortCircuitTest will hang on either True or False, while shortCircuitTestFinite will not. In native elm, shortCircuitTest will only hang on False, as expected.
I structured these tests to isolate the question - is the second expression being evaluated or not - as cleanly as possible (the only difference between the two
shortCircutTest
functions is that one of them triggers an infinite loop if it does not short circuit.)Additionally, I think it may be difficult to implement short circuiting in the current IR structure, with curried function application. If you imagine the IR as:
Then the outer apply function needs some way to know that it should not evaluate its second argument. There are ways to work around this, but I wonder if it wouldn't be better to have boolean operators present directly as members of Value?
Beta Was this translation helpful? Give feedback.
All reactions