If you have been following the exercises you should have an almost complete encoding of Ola’s syntax and typing rules. Some extra exercises follow:

Add Type Annotations and Products/Pairs

Extend your mechanisation to include the following data structures and operations:

Type Annotations

Type annotations, ensuring that an expression has a specific type

e := (the t e) ...
g |- e : t

---- [ Annotations ]

g |- (the t e) : t

Product Types

Pairs with two values, together with primitives to access the first and second element;

t := (t,t) ...
e := (e,e) | fst e | snd e ...
g |- l : t_{l}
g |- r : t_{r}

---- [ New Pair ]

g |- (l,r) : (t_{l}, t_{r})
g |- e : (t_{l},t_{r})

---- [ First ]

g |- fst e : t_{l}
g |- e : (t_{l},t_{r})

---- [ Second ]

g |- snd e : t_{r}

Sum Types

Extend your mechanisation further to support sums:

t := <t,t> ...
e := Left e | Right e ...
s := match e { Left xref => s; Right xref => s }
g |- e : t_{l}

---- [ Left ]

g |- e : <t_{l},t_{r}>
g |- e : t_{r}

---- [ Right ]

g |- e : <t_{l},t_{r}>
g                |- e : <t_{l},t_{r}>
g, (lref, t_{l}) |- l : t
g, (rref, t_{r}) |- r : t

---- [ Match ]

g |- match e { Left lref => l; Right rref => r }