let car list = match list with | Nil -> -1 | (One x | Cons (x,_)) -> x |
One x | Cons (x,_)
”
into two clauses with patterns
“One x
” and “Cons (x,_)
”.
Actions for the new clauses are
exits to 2:
catch
C((list), (
|
catch
... with (2 x) …
construct allocates
one mutable variable; an exit updates this variable, which is read
before entering the handler.
In a native code compiler, such a variable is a temporary and
ultimately a machine register.
The generated lambda-code is as follow:
catch switch* list with case Nil: -1 case One: (exit 2 (field 0 list)) case Cons: (exit 2 (field 0 list)) with (2 x) x |
P → L = |
|
(exit 1)
(the static exception label corresponding to match failure
can be given as a third argument to the compilation scheme).
Writing p1 = (1|2) and q1 = (3|4),
there are obviously no value vectors (v1 v2) such that
v1 is an instance of both p1 and q1.
As a consequence, the following compilation is correct:
catch
(catch
(switch x with
case 1: (exit 2) case 2: (exit 2)
case 3: (exit 3) case 4: (exit 3)
default: (exit 1))
with (2) C((y), (
|
catch
(catch
(switch x with
case 1: (exit 2) case 2: (exit 2)
default: (exit 3))
with (2) C((y), (
|
⎛ ⎜ ⎜ ⎜ ⎝ |
|
⎞ ⎟ ⎟ ⎟ ⎠ |