Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* sat.ml *)
- open BooleanExpression;;
- let e = `And( [`Or([`Var( 1 ); `Var(3)]);`Var( 0 );`Var(3)] ) in
- print_string (string_of_boolean_expression e);;
- print_newline();
- (* booleanExpression.ml *)
- type 'canonical boolean_expression = [
- `Var of int |
- `Not of 'canonical boolean_expression |
- `And of 'canonical boolean_expression list |
- `Or of 'canonical boolean_expression list
- constraint 'canonical = [ < `Canonical | `Not_canonical ]
- ];;
- let rec number_of_variables e =
- match e with
- | `Var i -> i
- | `Not t -> number_of_variables t
- | `And l | `Or l -> List.fold_left (fun m t -> max m (number_of_variables t)) 0 l
- ;;
- let rec string_of_boolean_expression e =
- let string_of_boolean_expression_list o l =
- match l with
- | [] -> ""
- | h :: t ->
- let rec loop l s =
- match l with
- | [] -> s
- | h :: t ->
- loop t (s ^ o ^ (string_of_boolean_expression h))
- in "(" ^ (string_of_boolean_expression h) ^ (loop t "") ^ ")"
- in
- match e with
- | `Var( i ) -> string_of_int i
- | `Not( sub_e ) -> "¬" ^ (string_of_boolean_expression sub_e)
- | `And l -> string_of_boolean_expression_list "∧" l
- | `Or l -> string_of_boolean_expression_list "∨" l
- ;;
- (* booleanExpression.mli *)
- type 'canonical boolean_expression constraint 'canonical = [< `Canonical | `Not_canonical ]
- val string_of_boolean_expression : _ boolean_expression -> string
- (* output *)
- File "sat.ml", line 4, characters 43-44:
- Error: This expression has type
- [> `And of [> `Or of [> `Var of int ] list | `Var of int ] list ]
- but an expression was expected of type
- [< `Canonical | `Not_canonical ]
- BooleanExpression.boolean_expression
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement