Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r @"dict.dll"
- open dict
- // ii
- let env1 = insert "x" 1 empty
- let env2 = insert "y" 2 env1
- let env3 = insert "a" 10 env2
- let env4 = insert "h" 5 env3
- let env5 = insert "d" 7 env4
- lookup "x" env5
- lookup "d" env5
- toList env5
- // iii
- type aexp =
- | C of int
- | V of string
- | Sum of aexp * aexp
- | Def of string * aexp * aexp
- let e1 = Def( "z" , Sum(V "x", C 10), Sum(V "y", V "z") )
- let e2 = Def( "x" , C 100 , Sum(V "x", V "y") )
- let rec aeval t env =
- match t with
- | C n -> n
- | V s -> lookup s env
- | Sum(t1,t2) -> aeval t1 env + aeval t2 env
- | Def(x,e1,e2) -> aeval e2 (insert x (aeval e1 env) env)
- aeval e1 env5
- aeval e2 env5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement