-- embed logical variables into a data structure data Type = TInt | TBool | TFun Type Type | TVar MVar -- wrap a pre-existing structure with logical variable, e.g. L [a] data L a = LV MVar | V a
We can devise rules that match the semantic rules for a given problem, such as type inference. Below is an example that shows how to express the type checking rule for applications.
app (env, (App e1 e2)) = do [a,b] <- newVars 2
(env, e1) .>. Fun a b
(env, e2) .>. a
return b
The DSEL provides a built-in inference function which runs the rule system on
a given input, returning all possible successful matches of the rules.
> infer ([] :: Env, Lam "x" (Var "x")) [Fun (TVar (MVar 2)) (TVar (MVar 2))]
To use the DSEL:
ghci -fglasgow-exts TypeLam.hs
*TypeLam> infer ([]::Env, Lam "x" (Lam "y" (App (Var "x") (Var "y")))) [Fun (Fun (TVar (MVar 5)) (TVar (MVar 6))) (Fun (TVar (MVar 5)) (TVar (MVar 6)))]
Haskell Rules: Embedding Rule Systems in Haskell, Steve Kollmansberger and Martin Erwig, Draft Paper, June 2006
| last change: January 20, 2013 | Martin Erwig  erwig@eecs.oregonstate.edu |