SHARE
TWEET

Untitled

a guest Apr 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. open Tfbsrxast;;
  2. open Tfbsrxpp;;
  3.  
  4. exception TypeError
  5.  
  6. (*
  7.  * If you would like typechecking to be enabled by your interpreter by default,
  8.  * then change the following value to true.  Whether or not typechecking is
  9.  * enabled by default, you can explicitly enable it or disable it using
  10.  * command-line arguments.
  11.  *)
  12. let typecheck_default_enabled = true;;
  13.  
  14. (*
  15.  * Replace this with your typechecker code.  Your code should not throw the
  16.  * following exception; if you need to raise an exception, create your own
  17.  * exception type here.
  18.  *)
  19.  
  20. let rec typecheck_aux gamma e = match e with
  21.     | Var(ident) -> TInt
  22.     | Function(ident, fbtype, expr) -> TInt
  23.     | Letrec(ident, ident2, fbtype, expr1, fbtype2, expr2) -> TInt
  24.     | Appl(expr1, expr2) -> TInt
  25.     | Plus(expr1, expr2) ->
  26.         if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
  27.         then TInt else raise TypeError
  28.     | Minus(expr1, expr2) ->
  29.         if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
  30.         then TInt else raise TypeError
  31.     | Equal(expr1, expr2) ->
  32.         if (typecheck_aux gamma expr1 = TInt && typecheck_aux gamma expr2 = TInt)
  33.         then TInt else raise TypeError
  34.     | And(expr1, expr2) -> TInt
  35.     | Or(expr1, expr2) -> TInt
  36.     | Not(expr1) -> TInt
  37.     | If(expr1, expr2, expr3) -> TInt
  38.     | Int(int) -> TInt
  39.     | Bool(bool) -> TBool
  40.     | Ref(expr) -> TInt
  41.     | Set(expr1, expr2) -> TInt
  42.     | Get(expr) -> TInt
  43.     | Record(recordlist) -> TInt
  44.     | Select(label, expr) -> TInt
  45.     | Raise(exnid, fbtype, expr) -> TInt
  46.     | Try(expr1, exnid, ident, fbtype, expr2) -> TInt
  47.     | Cell(int) -> TInt
  48. ;;
  49.  
  50. let typecheck e = typecheck_aux [] e;;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top