Safe Haskell | None |
---|---|
Language | Haskell98 |
This module defines the syntax of the simple, continuation-passing-style functional language used here, as well as some examples.
- type Prog = Lambda
- newtype Label = Label Integer
- data Var = Var Label String
- binder :: Var -> Label
- data Lambda = Lambda Label [Var] Call
- data Call
- data Val
- type Const = Integer
- data Prim
- newtype Inv a = Inv {
- unsafeFinish :: a
- prog :: Inv Lambda -> Prog
- lambda :: [Inv Var] -> Inv Call -> Inv Lambda
- app :: Inv Val -> [Inv Val] -> Inv Call
- let_ :: [(Inv Var, Inv Lambda)] -> Inv Call -> Inv Call
- l :: Inv Lambda -> Inv Val
- c :: Const -> Inv Val
- plus :: Inv Val
- if_ :: Inv Val
- noProg :: a
- ex1 :: Prog
- ex2 :: Prog
- ex3 :: Prog
- ex4 :: Prog
- puzzle :: Prog
The CPS styntax
A program is defined as a lambda abstraction. The calling convention is that the program has one paramater, the final continuation.
Labels are used throughout the code to refer to various positions in the code.
Integers are used here, but they are wrapped in a newtype to hide them from the implementation.
Variable names are just strings. Again, they are wrapped so they can be treated abstractly. They also carry the label of their binding position.
A lambda expression has a label, a list of abstract argument names and a body.
The body of a lambda expression is either
A value can either be
Primitive operations. The primitive operations are annotated by labels. These mark the (invisible) call sites that call the continuations, and are one per continuation.
Smart constructors
This wrapper marks values created using the smart constructors that are
not yet finished by passing them to prog
and therefore invalid.
Inv | |
|
prog :: Inv Lambda -> Prog Source
This converts code generated by the smart constructors below to a fully
annotated CPSScheme
syntax tree, by assigning labels and resolving references