A research blog about programming languages, databases, provenance, and other randomly-selected topics.

Wednesday, July 10, 2013

Exploring the compiler forest in Haskell

The combinators from the Compiler Forest paper can be implemented in Haskell as follows. (Note: This requires recent GHC with options -XKindSignatures -XGADTs -XTypeFamilies.) First, we define a type for partial compilers:

data PC :: * -> * -> * where PC :: (s -> (s', t' -> t)) -> PC (s,t) (s', t')In Haskell terms, this is a "generalized algebraic data type", but this is solely so that we can think of PC as a two-argument type constructor instead of four.
We can introduce type families for extracting the source and target types from a pair:type family Src atype instance Src (s,t) = s