Haskell Rules: Embedding Rule Systems in Haskell

Version: June 2006

-- 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] . Fun a b (env, e2) .>. a return b

> infer ([] :: Env, Lam "x" (Var "x")) [Fun (TVar (MVar 2)) (TVar (MVar 2))]

To use the DSEL:

Download HaskellRules-jun06.tar.gz

Gunzip and untar the archive. This will create a directory HaskellRules-jun06 . Change to that directory.

. Change to that directory. Start GHC and load an example file. You must use GHC 6.2 or 6.4 If you are using GHC 6.2, first read the file readme.txt for a small change to TypeGU.hs . Note that you have to use the flag -fglasgow-exts . ghci -fglasgow-exts TypeLam.hs

for a small change to . Note that you have to use the flag . Formulate queries. For example, What is the type of the expression λ x . λ y . x y? *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)))]

Further Information

Haskell Rules: Embedding Rule Systems in Haskell, Steve Kollmansberger and Martin Erwig, Draft Paper, June 2006

Contact