spacepaste

  1.  
  2. module type SF = sig
  3. type elt
  4. module S: Set.S with type elt = elt
  5. val of_list: S.elt list -> S.t
  6. val map: (S.elt -> S.elt) -> S.t -> S.t
  7. val ppr: Format.formatter -> S.t -> unit
  8. end
  9. module SetFuns (OT: Map.OrderedType) (SBLE: STRINGABLE with type t = OT.t) : (SF with type elt = OT.t) =
  10. struct
  11. module S = Set.Make(OT)
  12. let of_list l = List.fold_right S.add l S.empty
  13. (* map from Set to Set of the same type. currying heaven. *)
  14. let map f s = S.fold (fun x -> S.add (f x)) s S.empty
  15. let ppr ff s =
  16. Format.fprintf ff "@[{";
  17. ppr_list_inners (
  18. fun ff x ->
  19. Format.fprintf ff "%s" (SBLE.to_string x);
  20. ) ff (S.elements s);
  21. Format.fprintf ff "}@]"
  22. end
  23.