3
$\begingroup$

I am studying A simple type-theoretic language: MiniTT, which introduces a dependently typed language with The language contains data types, mutual recursive/inductive definitions and a universe of small types. The type checking proceeds by a mostly-straightforward bidirectional type-checking, coupled with normalization-by-evaluation to compute normal forms. It is here that I am confused. First, some quick syntax:

A sum type is created using Sum(c1 A1, ..., cn An), which contains objects of the form ci E : Sum(c1 A1, ..., cn An), where E: Ai. For example, booleans are encoded as Sum(true 1, false 1) where 1 is the unit type. The type of naturals is encoded as rec Nat : U = Sum (zero | succ Nat). Sum types are eliminated using case-analysis, written as fun(c1 M1, ..., cn Mn), where each constructor is ci and the associated handler is Mi. For example, the elimination rule for booleans can be encoded as:

Bool : U = Sum (true | false)
elimBool : Π C:Bool → U. C false → C true → Π b:Bool. C b
= λ C.λ h0.λ h1.fun (true → h1 | false → h0)

and the elimination for naturals can be written as:

rec natrec: ΠC : Nat → U. C zero → (Πn:Nat . C n → C (succ n)) → Π n:Nat. C n
= λ C.λ a.λ g. fun (zero → a | succ n1 → g n1 (natrec C a g n1))

Now, I had always assumed that when implementing normalization-by-evaluation (NBE), the normal forms always consist of constructors, while the neutral values consist of eliminators, since an eliminator can get stuck if it does not know enough about its argument, while a constructor can always freely construct.

However, in the paper's implementation of NBE (given in the appendix), it appears that Fun (labelled sum eliminators) are one of the normal forms:

data Val =
Lam Clos
 ...
| Fun SClos -- function is a normal form?!
...
| Nt Neut
deriving Show

Furthermore, the inductive data type of stuck/neutral values has yet another encoding of a stuck fun, called as NtFun:

data Neut = Gen Int
...
| NtFun SClos Neut -- Fun as a stuck term

I have not seen an explanation of NBE which allows one to encode a particular syntactic category (in this case, the labelled sum eliminator fun), as both a normal form and a neutral/stuck term.

  1. What is going on here? Why can a fun be both a normal form and a stuck/neutral term?
  2. How should I think about what my normal forms and stuck terms should be? I had previously imagined that constructors would be normal forms, and eliminators are stuck terms. What's the rule of thumb that's being followed here?
$\endgroup$
3
  • 1
    $\begingroup$ I think your intuition for neutral terms is not quite right: it's terms which cannot create new reductions when substituted in an evaluation context. E.g. $$\lambda. x. x$$ creates a new evaluation when put in the context $$[\_]\ t$$. $\endgroup$ – cody May 20 at 21:33
  • $\begingroup$ @cody What is the definition of "context" here? It is not the same as the typing judgement context Γ ⊢ ... is it? $\endgroup$ – Siddharth Bhat May 21 at 11:48
  • 1
    $\begingroup$ No it's an evaluation context, i.e. a term with a hole, in which to put the "thing I am currently evaluating". See e.g. these slides by Andrew Myers: courses.cs.cornell.edu/cs6110/2009sp/lectures/lec08-sp09.pdf $\endgroup$ – cody May 21 at 12:59
3
$\begingroup$

They are different things. SClos is a case-split function, which is a function that pattern match on its parameter. Think of it as a lambda (if you know Haskell, you can think of it as a LambdaCase \case, which is a sugared lambda). This is definitely a canonical value in Mini-TT.

The neutral value, OTOH, is an application on a case-split function, where the argument supplied is neutral. If an instance of a sum type is neutral, you don't know which constructor it belongs to, so you don't know which clause in the pattern matching should be selected, so this is a neutral value.

Summary: pattern matching itself is canonical, while application on pattern matching is not. If this application stucks, it becomes a neutral value.

$\endgroup$
1
  • 3
    $\begingroup$ Btw, I prefer the following definition of 'neutral value' (by induction): 0. A variable reference is a neutral value 1. Eliminating a neutral value gives a neutral value $\endgroup$ – ice1000 May 21 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.