2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: nCic.ml 9058 2008-10-13 17:42:30Z tassi $ *)
14 module type Elem = sig type t val pp : t -> string end ;;
16 module Make(T : Elem) = struct
18 type tree = Node of (T.t * tree) list
21 | Ctx of tree_ctx * (T.t * tree) list * T.t * (T.t * tree) list
24 type position = Loc of tree_ctx * tree
27 let start (t : tree) : position = Loc (Top, t);;
30 | Loc (_,Node []) -> None
31 | Loc (ctx, Node ((x,t)::tl)) -> Some (Loc (Ctx (ctx,[],x,tl),t))
36 | Loc (Ctx(ctx,l,x,r),t) -> Some (Loc (ctx,Node (l@[x,t]@r)))
40 | Loc (Top,_) | Loc (Ctx(_,_,_,[]),_) -> None
41 | Loc (Ctx(ctx,l,x,(rx,rt)::tl),t) -> Some (Loc(Ctx(ctx,l@[x,t],rx,tl),rt))
45 | Loc (Top,_) | Loc (Ctx(_,[],_,_),_) -> None
46 | Loc (Ctx(ctx,(lx,lt)::tl,x,r),t) -> Some (Loc(Ctx(ctx,tl,lx,(x,t)::r),lt))
49 let rec repeat f l = match f l with None -> l | Some l -> repeat f l;;
52 match repeat up t with
57 let previsit f acc (t : position) =
58 let rec aux acc = function
61 let acc = aux acc t in