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

Lazy evaluation of conditionals and boolean operators #77

Closed nhweston closed 2 years ago

nhweston commented 2 years ago

This PR ensures that conditional expressions and boolean operators adhere to the "lazy evaluation" behaviour expected of these constructs. To achieve these, both of these directly desugar to match expressions rather than function applications.

Conditional expressions:

if c then x else y

…desugar to:

c match {
  case True(_) => x
  case False(_) => y
}

Logical conjunction:

a && b

…desugars to:

a match {
  case True(_) => b
  case False(_) => << False = { } >>
}

Logical disjunction:

a || b

…desugars to:

a match {
  case True(_) => << True = { } >>
  case False(_) => b
}
nhweston commented 2 years ago

Good to merge this if you're happy with it. @inkytonik

inkytonik commented 2 years ago

LGTM, feel free to merge.