4 ms·
Methnks 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
by Blikkentrekker 6y ago
Methnks 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.