Fix example
This commit is contained in:
parent
06259e8abf
commit
e2b3f36a64
1 changed files with 12 additions and 7 deletions
|
|
@ -7,19 +7,24 @@ data Exp where
|
||||||
|
|
||||||
data Val where
|
data Val where
|
||||||
VInt : Int -> Val
|
VInt : Int -> Val
|
||||||
VClosure : List (Pair Char Val) -> Char -> Exp -> Val
|
VClosure : Cxt -> Char -> Exp -> Val
|
||||||
|
|
||||||
lookup : Char -> List (Pair Char Val) -> Val
|
data Cxt where
|
||||||
|
Cxt : List (Pair Char Val) -> Cxt
|
||||||
|
|
||||||
|
lookup : Char -> Cxt -> Val
|
||||||
lookup x cxt = case cxt of
|
lookup x cxt = case cxt of
|
||||||
|
Cxt ps => case ps of
|
||||||
Cons p ps => case p of
|
Cons p ps => case p of
|
||||||
Pair y v => case (asciiCode x) == (asciiCode y) of
|
Pair y v => case (asciiCode x) == (asciiCode y) of
|
||||||
True => v
|
True => v
|
||||||
False => lookup x ps
|
False => lookup x (Cxt ps)
|
||||||
|
|
||||||
insert : Char -> Val -> List (Pair Char Val) -> List (Pair Char Val)
|
insert : Char -> Val -> Cxt -> Cxt
|
||||||
insert x v cxt = Cons (Pair x v) cxt
|
insert x v cxt = case cxt of
|
||||||
|
Cxt ps => Cxt (Cons (Pair x v) ps)
|
||||||
|
|
||||||
eval : List (Pair Char Val) -> Exp -> Val
|
eval : Cxt -> Exp -> Val
|
||||||
eval cxt exp = case exp of
|
eval cxt exp = case exp of
|
||||||
EVar x => case lookup x cxt of
|
EVar x => case lookup x cxt of
|
||||||
VInt i => VInt i
|
VInt i => VInt i
|
||||||
|
|
@ -39,6 +44,6 @@ exp = EApp (EAbs 'x' (EVar 'x')) (EApp (EAbs 'x' (EAdd (EVar 'x') (EInt 100))) (
|
||||||
-- (λ x . x) (λ x . x + 100) 200
|
-- (λ x . x) (λ x . x + 100) 200
|
||||||
|
|
||||||
main : Int
|
main : Int
|
||||||
main = case eval Nil exp of
|
main = case eval (Cxt Nil) exp of
|
||||||
VInt i => i
|
VInt i => i
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue