# A Dependently Typed Core Language

Document Sample

```					A Dependently Typed Core Language
Robert Reitmeier
rxr@cs.nott.ac.uk

University of Nottingham

FoP Away Day – p. 1/1

Joint work with Simon Peyton Jones, much inspired by
Epigram
Haskell is evolving: Proof of concept for dependent types
Compiler for Epigram?!

FoP Away Day – p. 2/1
Overview

1. Basic Design Issues

2. Example Code

3. Screenshots

4. Future Work

FoP Away Day – p. 3/1
Basic Design Issues

Old school, non-interactive programming
General recursion =⇒ functions possibly non-total
(Problems?!)

FoP Away Day – p. 4/1
Primitive Types

Finite types (nullary constructors), e.g. {Zero , Succ }
Dependent pairs, e.g.

1     if l = Zero
nat :=     l : {Zero , Succ } ;
nat   if l = Succ
Dependent functions, e.g. append :
n1 : nat → n2 : nat → vec n1 → vec n2 → vec (n1 + n2 )
Type of types
Equality type a = b

FoP Away Day – p. 5/1
Heterogenous Equality

s0 : S0         s1 : S1
E Q F ORM
s0 = s1 :

s:S
E Q I NTRO
Reﬂ s : s = s

FoP Away Day – p. 6/1
Coercions

to state equality across propositionally equal type borders:

s : S0     p : S0 = S1
C OERCION [E Q ]
s |p : S1
s [[p| : s = s |p
Example:
append nil v2 := v2
but v2 : vec l2 instead of vec (0 + l2 ).
Given p : l2 = 0 + l2 , we can coerce v2 to

v2 |p : vec (0 + l2 )

FoP Away Day – p. 7/1
Example Code: leqNat

1   if x ≤ y ,
leqNat x y :=
∅   otherwise.

1   leqNat :    x:nat -> y:nat -> * ;
2   leqNat x    y = let (lx,x’) = x in case lx of
3       Zero    -> { () } ;
4       Succ    -> let (ly,y’) = y in case ly of
5              Zero -> { } ;
6              Succ -> leqNat x’ y’ ; ;
7   .

FoP Away Day – p. 8/1
Example Code: sub

Subtracts two natural numbers, given a proof that y ≤ x:

1   sub : x:nat -> y:nat -> p:leqNat y x -> nat
2   sub x y p = let (ly,y’) = y in case ly of
3       Zero -> x ;
4       Succ -> let (lx,x’) = x in case lx of
5           Zero -> case p of ;
6           Succ -> sub x’ y’ p ; ;
7   .

(BTW: Proof argument p can be erased at runtime)

FoP Away Day – p. 9/1
Type Checker GUI

FoP Away Day – p. 10/1
Evaluation GUI

FoP Away Day – p. 11/1
Future Work

Complete the implementation, give more examples
Prove soundness of the typing algorithm
High level compiler
Proof erasure

FoP Away Day – p. 12/1
End

FoP Away Day – p. 13/1

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 5 posted: 1/24/2011 language: English pages: 13
How are you planning on using Docstoc?