Advertisement
Guest User

es2.fsx

a guest
May 26th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.69 KB | None | 0 0
  1. #r @"dict.dll"
  2.  
  3.  
  4. open dict
  5.  
  6. // ii
  7.  
  8. let env1 = insert "x" 1 empty
  9. let env2 = insert "y" 2 env1
  10. let env3 = insert "a" 10 env2
  11. let env4 = insert "h" 5 env3
  12. let env5 = insert "d" 7 env4
  13.  
  14. lookup "x" env5
  15. lookup "d" env5
  16. toList env5
  17.  
  18. // iii
  19.  
  20. type aexp =
  21.   | C of int
  22.   | V of string
  23.   | Sum of aexp * aexp
  24.   | Def of string * aexp * aexp
  25.  
  26. let e1 = Def( "z" , Sum(V "x", C 10), Sum(V "y", V "z") )
  27. let e2 = Def( "x" , C 100 ,  Sum(V "x", V "y") )
  28.  
  29. let rec aeval t env =
  30.     match t with
  31.     | C n ->  n
  32.     | V s ->  lookup s env
  33.     | Sum(t1,t2)   -> aeval t1 env + aeval t2 env
  34.     | Def(x,e1,e2) -> aeval e2 (insert x (aeval e1 env) env)
  35.  
  36. aeval e1 env5
  37. aeval e2 env5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement