+ | l -> Layout (Box ((H, false, false), l))
+
+let unboxify = function
+ | Layout (Box ((H, false, false), [ a ])) -> a
+ | l -> l
+
+let group = function
+ | [ a ] -> a
+ | l -> Layout (Group l)
+
+let ungroup =
+ let rec aux acc =
+ function
+ [] -> List.rev acc
+ | Layout (Group terms) :: terms' -> aux acc (terms @ terms')
+ | term :: terms -> aux (term :: acc) terms
+ in
+ aux []
+
+let dress ~sep:sauce =
+ let rec aux =
+ function
+ | [] -> []
+ | [hd] -> [hd]
+ | hd :: tl -> hd :: sauce :: aux tl
+ in
+ aux
+
+let dressn ~sep:sauces =
+ let rec aux =
+ function
+ | [] -> []
+ | [hd] -> [hd]
+ | hd :: tl -> hd :: sauces @ aux tl
+ in
+ aux
+
+let find_appl_pattern_uris ap =
+ let rec aux acc =
+ function
+ | UriPattern uri ->
+ (try
+ ignore (List.find (fun uri' -> UriManager.eq uri uri') acc);
+ acc
+ with Not_found -> uri :: acc)
+ | ImplicitPattern
+ | VarPattern _ -> acc
+ | ApplPattern apl -> List.fold_left aux acc apl
+ in
+ aux [] ap
+
+let rec find_branch =
+ function
+ Magic (If (_, Magic Fail, t)) -> find_branch t
+ | Magic (If (_, t, _)) -> find_branch t
+ | t -> t
+
+let cic_name_of_name = function
+ | CicNotationPt.Ident ("_", None) -> Cic.Anonymous
+ | CicNotationPt.Ident (name, None) -> Cic.Name name
+ | _ -> assert false
+
+let name_of_cic_name =
+ let add_dummy_xref t = CicNotationPt.AttributedTerm (`IdRef "", t) in
+ function
+ | Cic.Name s -> add_dummy_xref (CicNotationPt.Ident (s, None))
+ | Cic.Anonymous -> add_dummy_xref (CicNotationPt.Ident ("_", None))
+
+let fresh_index = ref ~-1
+
+type notation_id = int
+
+let fresh_id () =
+ incr fresh_index;
+ !fresh_index
+
+ (* TODO ensure that names generated by fresh_var do not clash with user's *)
+let fresh_name () = "fresh" ^ string_of_int (fresh_id ())