rudimentary abstract syntax type checker and solver in PGF

This commit is contained in:
aarne
2008-10-14 14:34:08 +00:00
parent ec2d7e2299
commit e4dc63f665
6 changed files with 193 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ module PGF.Expr(readTree, showTree, pTree, ppTree,
tree2expr, expr2tree,
-- needed in the typechecker
Value(..), Env, eval,
Value(..), Env, eval, apply,
-- helpers
pIdent,pStr
@@ -188,6 +188,7 @@ data Value
| VMeta Int
| VLit Literal
| VClosure Env Expr
deriving (Show,Eq,Ord)
type Env = Map.Map CId Value
@@ -197,7 +198,10 @@ eval env (EApp e1 e2) = apply (eval env e1) (eval env e2)
eval env (EAbs x e) = VClosure env (EAbs x e)
eval env (EMeta k) = VMeta k
eval env (ELit l) = VLit l
eval env e = VClosure env e
apply :: Value -> Value -> Value
apply (VClosure env (EAbs x e)) v = eval (Map.insert x v env) e
apply v0 v = VApp v0 v