3.3 Problem: Types

► |  | Redex: Practical Semantics Engineering

1 | Amb: A Redex Tutorial
2 | Long Tutorial
3 | Extended Exercises
4 | The Redex Reference
5 | Automated Testing Benchmark
| Bibliography
| Index

▼ | 3 | Extended Exercises

3.1 | Problem: Objects
3.2 | Solution: Objects
3.3 | Problem: Types
3.4 | Solution: Types
3.5 | Problem: Missionaries and Cannibals
3.6 | Solution: Missionaries and Cannibals
3.7 | Problem: Towers of Hanoi
3.8 | Solution: Towers of Hanoi
3.9 | Problem: GC
3.10 | Solution: GC
3.11 | Problem: Finite State Machines
3.12 | Solution: Finite State Machines
3.13 | Problem: Threads
3.14 | Solution: Threads
3.15 | Problem: Contracts
3.16 | Solution: Contracts
3.17 | Problem: Binary Addition
3.18 | Solution: Binary Addition

Racket
top contents ← prev up next →

### 3.3 Problem: Types🔗ℹ

Design a reduction system that models type checking by reducing terms to their types. Formulate a metafunction that maps terms to types or #false:

> (define-metafunction TLambda-tc
> tc : e -> t or #false
> ; more here
> .....)

It produces #false when type checking fails.

You start with the normal term language:

> (define-language TLambda
> (e ::= n x (lambda (x t) e) (e e) (+ e e))
> (n ::= number)
> (t ::= int (t -> t))
> (x ::= variable-not-otherwise-mentioned))

The reduction systems gradually reduces terms to types, like this:

> (define type-checking
> (reduction-relation
> (--> (in-hole C n) (in-hole C int))
> (--> (in-hole C (+ int int)) (in-hole C int))
> ; you need more here
> .....))

Hint The key is to design a language of contexts that extends the given expression language so the reduction system can find all possible terms.

Consider adding if and let expressions to the language once you have the core model working.

top contents ← prev up next →