Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We can now write functions in a haskell-like equational style The following definition B/and : ∀(a: B/Bool) ∀(b: B/Bool) B/Bool | #True{} b = b | #False{} b = #False{} gets desugared to the equivalent match tree B/And : ∀(a: B/Bool) ∀(b: B/Bool) B/Bool = λ%x0 (λ{ #False: λ%x1 use b = %x1; #False{} #True: λ%x1 use b = %x1; b } %x0) All the variables are given unique generated names and then `use` terms are inserted at the correct spots to regain access to the original names. This is necessary to allow the same variable to have different names in the pattern-matching equation depending on the rule. It currently supports two types of patterns: Constructors and Variables. The patterns are desugared in a straight-forward way based on syntax alone. If we write the wrong number of arguments for a constructor or get the name of a constructor wrong, it'll result in a type error later. Also, although the logic for generating a default case of a match is implemented in the parser, the type checker doesn't support it yet. Pattern-matching functions with default cases will generate a match on a constructor called `#_` which will be unknown to the type checker. For example, this will be the desugaring for Bool/not using a default case: B/not : ∀(b: B/Bool) B/Bool | #False{} = #True{} | b = #False{} Becomes B/not : ∀(b: B/Bool) B/Bool = λ%x0 (λ{ #False: #True{} #_: use b = %x0; #False{} } %x0)
- Loading branch information