inkytonik / cooma

The Cooma project is investigating secure programming language design based on fine-grained object capabilities.
Mozilla Public License 2.0
3 stars 2 forks source link

If-then-else is not lazy in its arguments #74

Closed nhweston closed 2 years ago

nhweston commented 2 years ago

The branches of if-then-else expressions are not lazily evaluated.

For example, the following program:

fun (w: Writer)
  if true then w.write("true\n")
  else w.write("false\n")

…will write both "true" and "false" to the file.

This renders if-then-else unusable in many contexts, making algorithms difficult to write as conditionals need to be expressed using match expressions.

Is this something we want to fix? If-then-else expressions will probably need to desugar directly to match expressions instead of the ite function, since the invocation of a function necessitates eager evaluation.

A related problem is that boolean operators should short-circuit; they currently do not.

nhweston commented 2 years ago

Fixed by PR #77.