The abstract syntax for case is defined as follows, where e represents general expressions and g represents
Question:
The abstract syntax for case is defined as follows, where e represents general expressions and g represents guarded expressions:
Expressions (e) An expression in our language can be:
e ::= . . .
| case g end (expression of the type case)
Guarded Expressions (g) A guarded expression can have one of the following forms:
g ::= e ⇒ e (a simple guarded expression)
| g; g (a sequence of guarded expressions)
Semantics
The evaluation of the case operator is defined by the following process:
The guards of the guarded expressions are evaluated in sequential order from left to right.
If a guard evaluates to true, the associated expression is evaluated and its result becomes the result of the case operator.
If no guard is true, you can define default behavior or throw an error. In this document, we will define that the evaluation results in a special NoMatch error.
The formal notation for a guard that does not find a match could be expressed as:
case g end → error(NoMatch) if none ei ⇒⋆ true
Specifies the transition rules for how the case operator would work for operational semantics.
Develop typing rules that address the static semantics of the case operator.
It extends the type inference algorithm of Note 8 by incorporating constraint generation rules related to the case operator.
Can you explain the reason why the case operator is considered syntactic sugar in the language?
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba