Advertisement
Guest User

Untitled

a guest
Feb 16th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.13 KB | None | 0 0
  1. type aExp =
  2.  | N of int (*numbers*)
  3.  | V of string (*variables*)
  4.  | Add of aExp * aExp (* addition *)
  5.  | Mul of aExp * aExp (* multiplication *)
  6.  | Sub of aExp * aExp;; (* subtraction *)
  7.  
  8. type bExp =
  9.  | TT
  10.  | FF
  11.  | Eq of aExp * aExp
  12.  | Lt of aExp * aExp (*less than*)
  13.  | Neg of bExp
  14.  | Con of bExp * bExp;; (*conjunction*)
  15.  
  16. type stm =
  17.  | Ass of string * aExp
  18.  | Skip
  19.  | Seq of stm * stm
  20.  | ITE of bExp * stm * stm
  21.  | While of bExp * stm
  22.  | IT of bExp * stm
  23.  | RepeatUntil of bExp * stm
  24.  | Inc of string;;
  25.  
  26. let rec A a s =
  27.  match a with
  28.  | N i -> i
  29.  | V x -> Map.find x s
  30.  | Add(a1, a2) -> A a1 s + A a2 s
  31.  | Mul(a1, a2) -> A a1 s * A a2 s
  32.  | Sub(a1, a2) -> A a1 s - A a2 s;;
  33.  
  34. let rec B b s =
  35.  match b with
  36.  | TT -> true
  37.  | FF -> false
  38.  | Eq(a1, a2) -> A a1 s = A a2 s
  39.  | Lt(a1, a2) -> A a1 s < A a2 s
  40.  | Neg(b) -> not(B b s)
  41.  | Con(a1, a2) -> B a1 s && B a2 s;;
  42.  
  43. let rec I stm s =
  44.  match stm with
  45.  | Ass(x,a) -> update x (A a s) s
  46.  | Skip -> s
  47.  | Seq(stm1, stm2) -> I stm2 (I stm1 s)
  48.  | ITE(b, stm1, stm2) -> if B b s then I stm1 s else I stm2 s
  49.  | While(b, stm') -> if B b s then I stm (I stm' s) else s;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement