Advertisement
xavierm02

Untitled

Dec 12th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.24 KB | None | 0 0
  1. (* booleanExpression.ml *)
  2. type 'canonical boolean_expression = [
  3.   `Variable of int |
  4.   `Not of 'canonical boolean_expression |
  5.   `And of 'canonical boolean_expression list |
  6.   `Or of 'canonical boolean_expression list
  7. ];;
  8.  
  9. let rec string_of_boolean_expression e =
  10.   let string_of_boolean_expression_list o l =
  11.     match l with
  12.       | [] -> ""
  13.       | h :: t ->
  14.         let rec loop l s =
  15.           match l with
  16.             | [] -> s
  17.             | h :: t ->
  18.               loop t (s ^ o ^ (string_of_boolean_expression h))
  19.         in "(" ^ (string_of_boolean_expression h) ^ (loop t "") ^ ")"
  20.   in
  21.   match e with
  22.     | `Variable( i ) -> string_of_int i
  23.     | `Not( sub_e ) -> "¬" ^ (string_of_boolean_expression sub_e)
  24.     | `And l -> string_of_boolean_expression_list "∧" l
  25.     | `Or l -> string_of_boolean_expression_list "∨" l
  26. ;;
  27.  
  28. type not_canonical_boolean_expression = [`Not_canonical] boolean_expression;;
  29.  
  30. (* booleanExpression.mli *)
  31. type not_canonical_boolean_expression = [
  32.   `Variable of int |
  33.   `Not of not_canonical_boolean_expression |
  34.   `And of not_canonical_boolean_expression list |
  35.   `Or of not_canonical_boolean_expression list
  36. ];;
  37.  
  38. val string_of_boolean_expression : not_canonical_boolean_expression -> string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement