Guest User

Untitled

a guest
Oct 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.57 KB | None | 0 0
  1. type aexpr =
  2.     | CstI of int
  3.     | Var of string
  4.     | Add of aexpr * aexpr
  5.     | Mul of aexpr * aexpr
  6.     | Sub of aexpr * aexpr;;
  7.  
  8. // Sub(Var "v", Add(Var "w", Var "z"));;
  9. // Mul(CstI 2, Sub(Var "v", Add(Var "w", Var "z"));;
  10. // Add(Var "x", Add(Var "y", Add(Var "z", Var "v")));;
  11.  
  12. let rec fmt ae : string =
  13.     match ae with
  14.     | CstI i -> i.ToString()
  15.     | Var x -> x
  16.     | Add(ae1, ae2) -> "(" + fmt(ae1) + " + " + fmt(ae2) + ")"
  17.     | Mul(ae1, ae2) -> "(" + fmt(ae1) + " * " + fmt(ae2) + ")"
  18.     | Sub(ae1, ae2) -> "(" + fmt(ae1) + " - " + fmt(ae2) + ")";;
Add Comment
Please, Sign In to add comment