+let ppterm ~formatter:f ~context ~subst ~metasenv:_ ?(inside_fix=false) t =
+ let rec aux ?(toplevel=false) ctx = function
+ | C.Rel m ->
+ (try
+ let name = List.nth ctx (m-1) in
+ F.fprintf f "%s" (if name = "_" then "__"^string_of_int m else name)
+ with Failure "nth" | Invalid_argument "List.nth" ->
+ F.fprintf f " -%d" (m - List.length ctx))
+ | C.Const r -> F.fprintf f "%s" (r2s inside_fix r)
+ | C.Prod ("_",s,t) ->
+ if not toplevel then F.fprintf f "(";
+ F.fprintf f "@[<hov 1>";
+ (match s with
+ | C.Prod ("_",_,_) -> aux ~toplevel:false ctx s
+ | _ -> aux ~toplevel:true ctx s);
+ F.fprintf f "@;→ ";
+ aux ~toplevel:true ("_"::ctx) t;
+ F.fprintf f "@]";
+ if not toplevel then F.fprintf f ")";
+ | C.Prod (name,s,t) ->
+ if not toplevel then F.fprintf f "(";
+ F.fprintf f "@[<hov 1>";
+ F.fprintf f "@[<hov 2>∀%s:@;" name;
+ aux ~toplevel:true ctx s;
+ F.fprintf f "@].@;";
+ aux ~toplevel:true (name::ctx) t;
+ F.fprintf f "@]";
+ if not toplevel then F.fprintf f ")";
+ | C.Lambda (name,s,t) ->
+ if not toplevel then F.fprintf f "(";
+ F.fprintf f "@[<hov 1>";
+ F.fprintf f "λ%s:" name;
+ aux ~toplevel:true ctx s;
+ F.fprintf f ".@;";
+ aux ~toplevel:true (name::ctx) t;
+ F.fprintf f "@]";
+ if not toplevel then F.fprintf f ")";
+ | C.LetIn (name,ty,t,b) ->
+ if not toplevel then F.fprintf f "(";
+ F.fprintf f "@[<hov 1>";
+ F.fprintf f "let %s:@;" name;
+ aux ~toplevel:true ctx ty;
+ F.fprintf f "@;≝ ";
+ aux ~toplevel:true ctx t;
+ F.fprintf f "@;in@;";
+ (aux ~toplevel:true (name::ctx) b);
+ F.fprintf f "@]";
+ if not toplevel then F.fprintf f ")";
+ | C.Match (r,oty,t,pl) ->
+ F.fprintf f "@[<hov>match ";
+ aux ~toplevel:true ctx t;
+ F.fprintf f "@;return ";
+ aux ~toplevel:true ctx oty;
+ F.fprintf f "@; @[<v>[ ";
+ if pl <> [] then
+ begin
+ F.fprintf f "@[<hov 2>%s ⇒@;"
+ (try r2s inside_fix (R.mk_constructor 1 r)
+ with R.IllFormedReference _ -> "#ERROR#");
+ aux ~toplevel:true ctx (List.hd pl);
+ F.fprintf f "@]";
+ ignore(List.fold_left
+ (fun i t ->
+ F.fprintf f "@;| @[<hov 2>%s ⇒@;"
+ (try r2s inside_fix (R.mk_constructor i r)
+ with R.IllFormedReference _ -> "#ERROR#");
+ aux ~toplevel:true ctx t;
+ F.fprintf f "@]";
+ i+1)
+ 2 (List.tl pl));
+ end;
+ F.fprintf f "]@] @]";
+ | C.Appl [] ->
+ F.fprintf f "BAD APPLICATION: empty list"
+ | C.Appl [x] ->
+ F.fprintf f "BAD APPLICATION: just the head: ";
+ aux ctx x
+ | C.Appl (C.Appl _ as x::_) ->
+ F.fprintf f "BAD APPLICATION: appl of appl with head: ";
+ aux ctx x
+ | C.Appl (C.Meta (n,lc) :: args) when List.mem_assoc n subst ->
+ let _,_,t,_ = List.assoc n subst in
+ let hd = NCicSubstitution.subst_meta lc t in
+ aux ctx
+ (!head_beta_reduce ~upto:(List.length args)
+ (match hd with
+ | NCic.Appl l -> NCic.Appl (l@args)
+ | _ -> NCic.Appl (hd :: args)))
+ | C.Appl l ->
+ F.fprintf f "@[<hov 2>";
+ if not toplevel then F.fprintf f "(";
+ aux ctx (List.hd l);
+ List.iter (fun x -> F.fprintf f "@;";aux ctx x) (List.tl l);
+ if not toplevel then F.fprintf f ")";
+ F.fprintf f "@]"
+ | C.Implicit annot ->
+ F.fprintf f "?%s" (string_of_implicit_annotation annot)
+ | C.Meta (n,lc) when List.mem_assoc n subst ->
+ let _,_,t,_ = List.assoc n subst in
+ aux ctx (NCicSubstitution.subst_meta lc t)
+ | C.Meta (n,(shift,C.Irl len)) ->
+ F.fprintf f "?%d(%d,%d)" n shift len
+ | C.Meta (n,(shift,C.Ctx l)) ->
+ F.fprintf f "?%d(%d,[" n shift;
+ if List.length l > 0 then
+ begin
+ aux ctx (NCicSubstitution.lift shift (List.hd l));
+ List.iter (fun x -> F.fprintf f ",";aux ctx x)
+ (List.map (NCicSubstitution.lift shift) (List.tl l));
+ end;
+ F.fprintf f "])"
+ | C.Sort s -> NCicEnvironment.ppsort f s
+ in
+ aux ~toplevel:true (List.map fst context) t