ErgoTree Evaluation

Evaluation of ErgoTree\mathrm{ErgoTree} is specified by its translation to Core-λ\mathrm{Core\text{-}\lambda}, whose terms form a subset of ErgoTree\mathrm{ErgoTree} terms. Thus, typing rules of Core-λ\mathrm{Core\text{-}\lambda}form a subset of typing rules of ErgoTree\mathrm{ErgoTree}.

Here we specify evaluation semantics of Core-λ\mathrm{Core\text{-}\lambda}, which is based on call-by-value (CBV) lambda calculus. Evaluation of Core-λ\mathrm{Core\text{-}\lambda} is specified using denotational semantics. To do that, we first specify denotations of types, then typed terms and then equations of denotational semantics.

Definition 1

The following Core-λ\mathrm{Core\text{-}\lambda} terms are called values:

V:==xC(d,T)λx.MV :== x \mid C(d, T) \mid \lambda x.M

All Core-λ\mathrm{Core\text{-}\lambda} terms are called producers. (This is because, when evaluated, they produce a value.)

We now describe and explain a denotational semantics for the Core-λ\mathrm{Core\text{-}\lambda} language. The key principle is that each type AA denotes a set [ ⁣[A] ⁣][\![A]\!] whose elements are the denotations of values of the type AA.

Thus the type Boolean\mathrm{Boolean} denotes the 2-element set {true,false}\{\mathrm{true},\mathrm{false}\}, because there are two values of type Boolean\mathrm{Boolean}. Likewise the type (T1,,Tn)(T_1,\dots,T_n)denotes ([ ⁣[T1] ⁣],,[ ⁣[Tn] ⁣])([\![T_1]\!],\dots,[\![T_n]\!]) because a value of type (T1,,Tn)(T_1,\dots,T_n)must be of the form (V1,,Vn)(V_1,\dots,V_n), where each ViV_i is value of type TiT_i.

Given a value VV of type AA, we write [ ⁣[V] ⁣][\![V]\!] for the element of AA that it denotes. Given a close term MM of type AA, we recall that it produces a value VV of type AA. So MM will denote an element [ ⁣[M] ⁣][\![M]\!] of [ ⁣[A] ⁣][\![A]\!].

A value of type ABA \to B is of the form λx.M\lambda x.M. This, when applied to a value of type AA gives a value of type BB. So ABA \to B denotes[ ⁣[A] ⁣][ ⁣[B] ⁣][\![A]\!] \to [\![B]\!]. It is true that the syntax appears to allow us to apply λx.M\lambda x.Mto any term NN of type AA. But NN will be evaluated before it interracts with λx.M\lambda x.M, so λx.M\lambda x.M is really only applied to the value that NN produces.

Definition 2

A context Γ\Gamma is a finite sequence of identifiers with valuetypesx1:A1,,xn:Anx_1:A_1, \dots ,x_n:A_n. Sometimes we omit the identifiers and write Γ\Gammaas a list of value types.

  • Given a context Γ=x1:A1,,xn:An\Gamma = x_1:A_1,\dots,x_n:A_n, an environment (list of bindings for identifiers) associates to each xix_i as value of type AiA_i. So the environment denotes an element of ([ ⁣[A1] ⁣],,[ ⁣[An] ⁣])([\![A_1]\!],\dots,[\![A_n]\!]), and we write [ ⁣[Γ] ⁣][\![\Gamma]\!] for this set.
  • Given a Core-λ\mathrm{Core\text{-}\lambda} term ΓM:B\Gamma \vdash M: B, we see that MM, together with environment, gives a closed term of type BB. So MM denotes a function [ ⁣[M] ⁣][\![M]\!] from [ ⁣[Γ] ⁣][\![\Gamma]\!] to [ ⁣[B] ⁣][\![B]\!].

In summary, the denotational semantics is organized as follows.

  • A type AA denotes a set [ ⁣[A] ⁣][\![A]\!]
  • A context x1:A1,,xn:Anx_1:A_1,\dots,x_n:A_n denotes the set ([ ⁣[A1] ⁣],,[ ⁣[An] ⁣])([\![A_1]\!],\dots,[\![A_n]\!])
  • A term ΓM:B\Gamma \vdash M: B denotes a function [ ⁣[M] ⁣][\![M]\!]: [ ⁣[Γ] ⁣][ ⁣[B] ⁣][\![\Gamma]\!] \to [\![B]\!]

The denotations of Core-λ\mathrm{Core\text{-}\lambda} types

[ ⁣[Boolean] ⁣]={true,false}[\![\mathrm{Boolean}]\!] = \{ \mathrm{true}, \mathrm{false} \}
[ ⁣[P] ⁣]=see set of values in Appendix A[\![\mathrm{P}]\!] = \text{see set of values in Appendix A}
[ ⁣[(T1,,Tn)] ⁣]=([ ⁣[T1] ⁣],,[ ⁣[Tn] ⁣])[\![(T_1,\dots,T_n)]\!] = ([\![T_1]\!],\dots,[\![T_n]\!])
[ ⁣[AB] ⁣]=[ ⁣[A] ⁣][ ⁣[B] ⁣][\![A \to B]\!] = [\![A]\!] \to [\![B]\!]

The denotations of Core-λ\mathrm{Core\text{-}\lambda} terms which together specify the function [ ⁣[_] ⁣]:[ ⁣[Γ] ⁣][ ⁣[T] ⁣][\![\_]\!]: [\![\Gamma]\!] \to [\![T]\!]

[ ⁣[x] ⁣](ρ,xx,ρ)=x[\![\mathrm{x}]\!]\langle(\rho,\mathrm{x}\mapsto x, \rho')\rangle = x
[ ⁣[C(d,T)] ⁣]ρ=d[\![C(d, T)]\!]\langle\rho\rangle = d
[ ⁣[(Mi)] ⁣]ρ=([ ⁣[Mi] ⁣]ρ)[\![(\overline{M_i})]\!]\langle\rho\rangle = (\overline{[\![M_i]\!]\langle\rho\rangle})
[ ⁣[δN] ⁣]ρ=([ ⁣[δ] ⁣]ρ)v where v=[ ⁣[N] ⁣]ρ[\![\delta\langle N\rangle]\!]\langle\rho\rangle = ([\![\delta]\!]\langle\rho\rangle)\langle v \rangle~\text{where}~v = [\![N]\!]\langle\rho\rangle
[ ⁣[λx.M] ⁣]ρ=λx.[ ⁣[M] ⁣](ρ,xx)[\![\lambda\mathrm{x}.M]\!]\langle\rho\rangle = \lambda x.[\![M]\!]\langle(\rho, \mathrm{x}\mapsto x)\rangle
[ ⁣[MfN] ⁣]ρ=([ ⁣[Mf] ⁣]ρ)v where v=[ ⁣[N] ⁣]ρ[\![M_f\langle N\rangle]\!]\langle\rho\rangle = ([\![M_f]\!]\langle\rho\rangle)\langle v \rangle~\text{where}~v = [\![N]\!]\langle\rho\rangle
[ ⁣[MI.mNi] ⁣]ρ=([ ⁣[MI] ⁣]ρ).mvi where vi=[ ⁣[Ni] ⁣]ρ[\![M_I.\mathrm{m}\langle\overline{N_i}\rangle]\!]\langle\rho\rangle = ([\![M_I]\!]\langle\rho\rangle).m\langle\overline{v_i}\rangle~\text{where}~\overline{v_i = [\![N_i]\!]\langle\rho\rangle}