cs252r : Advanced Functional Programming - Fall 2006

These pages are a record of the in-class discussions for the graduate class "Advanced Functional Programming" given at Harvard University in the Fall of 2006.

December 11, 2006


How far in the paper can you get just using GADTs? Which parts of the commutative diagram on page 8 can be expressed using GADTs, and which require the additional expressive power of Epigram?

data Nat = Zero | Succ Nat
data Val where
  Nat  :: Nat -> Val Nat
  Bool :: Bool -> Val Bool
data Exp a where
  Val  :: Val a -> Exp a
  Plus :: Exp Nat -> Exp Nat -> Exp NAt
  If   :: Exp Bool -> Exp a -> Exp a -> Exp a

type Epsilon = ()
(|>) :: a - b -> (a,b)
top  :: (a,b) -> a

data Code a b where
  Skip   :: Code a b
  (:++:) :: Code s0 s1 -> Code s1 s2 -> Code s0 s2
  Push   :: Val v -> Code s (v,s)
  Add    :: Code (Nat,(Nat,s)) (Nat,s)
  Ifc    :: Code s s' -> Code s s' -> Code (Bool,s) s'
 eval    :: Exp a -> Val a
 exec    :: Code s s' -> s -> s'
 compile :: Exp a -> Code s (a,s)
 correct :: ??? -- cannot express in Haskell.

The power of Epigram shows up (int this paper) when we reason in the type system about the equality of terms. The implementation of correct make use of terms in the type language, and these types are provably equal.

BibTeX

@Article{James-McKinna-and-Joel-Wright2006
  , url        = "http://www.cs.nott.ac.uk/~jjw"
  , title      = "A type-correct, stack-safe, provably correct, expression compiler in Epigram"
  , month      = "July"
  , note       = "submitted"
  , author     = "James McKinna and Joel Wright"
  , journal    = "Journal of Functional Programming"
  , year       = 2006
  }