Guest User

Context

a guest
Jan 28th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.85 KB | None | 0 0
  1. (* A context. *)
  2.  
  3. type context = Formula.formula list;;
  4.  
  5. let empty ():context = []
  6.  
  7. (**
  8.     @param c The context to extend.
  9.     @param n The formula to add.
  10. *)
  11. let extend (c:context) (n:Formula.formula):context =
  12.     if (List.exists (fun f -> (Formula.equals n f)) c) then c else n::c
  13.  
  14. let join (c1:context) (c2:context) =
  15.     List.fold_right (fun f c -> extend c f) c2 c1
  16.  
  17. let exists (c:context) (f:Formula.formula):bool =
  18.     List.exists (Formula.equals f) c
  19.  
  20. (**
  21.     @param p The parent context.
  22.     @param c The sub-context.
  23. *)
  24. let subcontext (p:context) (c:context):bool =
  25.     not (List.exists (fun x -> not (exists c x)) p)
  26.  
  27. let to_string (c:context):string =
  28.     match c with
  29.     | []    -> "[]"
  30.     | f::[] -> "[" ^ (Formula.to_string f) ^ "]"
  31.     | f::l  -> "[" ^ (Formula.to_string f) ^
  32.         (List.fold_right (fun f s -> s ^ ", " ^ Formula.to_string f) l "") ^ "]"
Advertisement
Add Comment
Please, Sign In to add comment