Start of topic | Skip to actions

Discussion of Next Topic

  1. List sorting
  2. More Coq
  3. Staged interpreters

We will study interpreters next.

Sets we talked about:

  1. e ::= x | \lambda x.e | e e | i \e \mathbb{E}
  2. t ::= int | t -> t \e \mathbb{T}
  3. \gamma \turn \dot : t

1 and 2 can be expressed as datatypes, 3 cannot. E and T are constants, while gamma and t are indices into the set. Given a particular gamma, x may not be typable, but this is not true in general.

An example of a similar set is List(t), which takes a t argument. However, it can be expressed as a datatype, while the previous cannot. For the previous set, you must examine the t argument to determine membership. To determine membership of List(t), you simply must prove the argument has type t.

  1. [] \in List(t)
  2. x::l \in List(t) iff x \in t, l \in List(t)

This is a very simple requirement, unlike the gamma term

e \in \gamma \turn \dot : t iff
  1. e \equiv x and \gamma (x)=t or
  2. e \equiv \lambda x.e and e \in \gamma,x:t1 \turn \dot : t2 and t \equiv t1->t2
  3. e \equiv e1 e2 and e1 \in \gamma \turn \dot : t1->t and e2 \in \gamma \turn e:t1
  4. e \equiv i and i \in Integer and t \equiv int

Typed terms are a subset of untyped terms in the same way balanced trees are a subset of trees, or sized lists are a subset of lists.

\gamma (x) = t
----------------
\gamma \turn x : t

\gamma , x:t1 \turn e: t2
----------------
\gamma \turn \lambda x.e : t1 -> t2

\gamma \turn e1 : t1 -> t2
\gamma \turn e2 : t1
----------------
\gamma \turn e1 e2 : t2

But we want to modify our BNF to simplify these rules. The modified BNF is:

n \in \mathbb{N}
e ::= #n | \lambda .e | e e | i
using static distance or De Bruijn naming.

Since variables are now defined by naturals, we can describe the case where e = #n using induction on the structure of the natural:

----------------
\gamma ,t \turn #0 : t

\gamma \turn #(n) : t
----------------
\gamma ,t' \turn #(n+1) : t
A trivial change needs to be made to the lambda case as well:
\gamma ,t1 \turn e: t2
----------------
\gamma \turn \lambda .e : t1 -> t2
Now we can write the concoqtion type to represent this:
type (env, typ) term = 
  | TVarZero 
      let env':envType in
    : (env' * typ, typ) term
  | TVarPlus
      let env':envType in
      let t':typeType in
        of (env, typ) term
    : (env' * t', typ) term
  | ...

Homework:

  1. Think about how to write lambda and application for next class.
  2. write three functions:
    1. typecheck : untyped -> term option
    2. untyped eval : uterm -> uenv -> uvalue option
    3. eval : (\gamma, t) term -> (evalEnv \gamma) -> (evalType t)
Put a type annotation on lambdas so typecheck can work. The typecheck function is analagous to size_it, which we wrote for sized lists. Eval takes a typing judgement and returns a type function that accepts an environment and returns a type.

End of topic
Skip to actions | Back to top
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.