3 ms·
The post says "there is no observable difference between calling a function and not using the result, and not calling it at all." But you just described an impo
by millstone 6y ago
The post says "there is no observable difference between calling a function and not using the result, and not calling it at all." But you just described an important difference!
In Haskell one must use the assertion's result to trip the assertion, which can be awkward. But Elm is strict; I wonder how assertions are treated in this sort of DCE.
- Blikkentrekker 6y agoMethnks you approach the control flow differently, as in for instance in pseudocode: assert(list.len() > 0); //code that assumes that the list not be empty Whereas in a functional language, what would happen is: if list.len() > 0 then // code assumes that the list not be empty else assertion_fail("list is not empty") Functional languages lack sequencing syntax that execute two expressions, ignoring the result of the first, altogether, and every function definition is one single expression. One does not as such first makes an assertion as the first element of a sequence, and then proceeds under the assumption that the assertion did not fail, but rather calls the `assertion_fail` function on some code paths, which then never returns if ever it be reached. The type system will call the function all the same, as as far as the type system and language runtime is concerned, it is an ordinary function that will return a value of the expected type, but under the hood it aborts the entire program, and prints proper diagnostics.