Guest User

Untitled

a guest
Jan 3rd, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.65 KB | None | 0 0
  1. let rec simple_string_of_boolean_expression =
  2.   function
  3.     | Var i -> string_of_int i
  4.     | Not (Var i) -> "¬" ^ string_of_int i
  5.     | Not e -> "¬(" ^ (simple_string_of_boolean_expression e) ^ ")"
  6.     | BinOp (l, o, r) -> (
  7.         match l with
  8.           | BinOp (_, lo, _) when lo <> o ->
  9.             "(" ^ simple_string_of_boolean_expression l ^ ")"
  10.           | _ -> simple_string_of_boolean_expression l
  11.       ) ^ (string_of_binary_operator o) ^ (
  12.         match r with
  13.           | BinOp (_, ro, _) when ro <> o ->
  14.             "(" ^ simple_string_of_boolean_expression r ^ ")"
  15.           | _ -> simple_string_of_boolean_expression r
  16.       )
  17. ;;
Advertisement
Add Comment
Please, Sign In to add comment