diff --git a/sample-programs/working/lambda_calculus-2.crf b/sample-programs/working/lambda_calculus-2.crf index 1d588ef..9df50b4 100644 --- a/sample-programs/working/lambda_calculus-2.crf +++ b/sample-programs/working/lambda_calculus-2.crf @@ -7,19 +7,24 @@ data Exp where data Val where 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 + Cxt ps => case ps of Cons p ps => case p of Pair y v => case (asciiCode x) == (asciiCode y) of True => v - False => lookup x ps + False => lookup x (Cxt ps) -insert : Char -> Val -> List (Pair Char Val) -> List (Pair Char Val) -insert x v cxt = Cons (Pair x v) cxt +insert : Char -> Val -> Cxt -> 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 EVar x => case lookup x cxt of 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 main : Int -main = case eval Nil exp of +main = case eval (Cxt Nil) exp of VInt i => i