Skip to content

Commit c41a752

Browse files
committed
code factorization in goal.ml
1 parent 37129e4 commit c41a752

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/handle/goal.ml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ let simpl : (ctxt -> term -> term) -> goal -> goal = fun f g ->
7575
Typ {gt with goal_type = f (Env.to_ctxt gt.goal_hyps) gt.goal_type}
7676
| Unif (c,t,u) -> Unif (c, f c t, f c u)
7777

78+
(** [typ_or_def idmap ppf (_,ty,def)] prints in [ppf] the type [ty] or the
79+
definition [def] if there is one. *)
80+
let typ_or_def idmap ppf (ty,def) =
81+
let term = term_in idmap in
82+
match def with
83+
| None -> out ppf "%a" term (Eval.snf_beta ty)
84+
| Some u -> out ppf "≔ %a" term u
85+
86+
(** [ctxt_elt idmap ppf x] prints in [ppf] the conttext element [x]. *)
87+
let ctxt_elt idmap ppf (v,ty,def) =
88+
out ppf "%a%a" var v (typ_or_def idmap) (ty,def)
89+
90+
(** [env_elt idmap ppf x] prints in [ppf] the environment element [x]. *)
91+
let env_elt idmap ppf (s,(_,ty,def)) =
92+
out ppf "%a%a" uid s (typ_or_def idmap) (ty,def)
93+
7894
(** [hyps ppf g] prints on [ppf] the beta-normal forms of the hypotheses of
7995
the goal [g]. *)
8096
let hyps : int StrMap.t -> goal pp =
@@ -85,23 +101,9 @@ let hyps : int StrMap.t -> goal pp =
85101
(List.pp (fun ppf -> out ppf "%a\n" elt) "") (List.rev l)
86102
in
87103
fun idmap ppf g ->
88-
let term = term_in idmap in
89104
match g with
90-
| Typ gt ->
91-
let elt ppf (s,(_,ty,def)) =
92-
match def with
93-
| None -> out ppf "%a: %a" uid s term (Eval.snf_beta ty)
94-
| Some u -> out ppf "%a ≔ %a" uid s term u
95-
in
96-
hyps elt ppf gt.goal_hyps
97-
| Unif (c,_,_) ->
98-
let elt ppf (x,a,t) =
99-
out ppf "%a: %a" var x term a;
100-
match t with
101-
| None -> ()
102-
| Some t -> out ppf " ≔ %a" term t
103-
in
104-
hyps elt ppf c
105+
| Typ gt -> hyps (env_elt idmap) ppf gt.goal_hyps
106+
| Unif (c,_,_) -> hyps (ctxt_elt idmap) ppf c
105107

106108
(** [concl ppf g] prints on [ppf] the beta-normal form of the conclusion of
107109
the goal [g]. *)
@@ -111,7 +113,8 @@ let concl : int StrMap.t -> goal pp = fun idmap ppf g ->
111113
| Typ gt ->
112114
out ppf "?%d: %a" gt.goal_meta.meta_key
113115
term (Eval.snf_beta gt.goal_type)
114-
| Unif (_, t, u) -> out ppf "%a ≡ %a" term t term u
116+
| Unif (_, t, u) ->
117+
out ppf "%a ≡ %a" term (Eval.snf_beta t) term (Eval.snf_beta u)
115118

116119
(** [pp ppf g] prints on [ppf] the beta-normal form of the goal [g] with its
117120
hypotheses. *)
@@ -133,26 +136,18 @@ let to_info : goal -> info =
133136
res
134137
in
135138
fun g ->
136-
let term = term_in (get_names g) in
139+
let idmap = get_names g in
140+
let term = term_in idmap in
137141
match g with
138142
| Typ gt ->
139-
let env_elt (s,(_,ty,def)) =
140-
s,
141-
match def with
142-
| None -> to_string term (Eval.snf_beta ty)
143-
| Some d -> ""^to_string term d
144-
in
145-
List.rev_map env_elt gt.goal_hyps,
143+
let f (s,(_,ty,def)) = s, to_string (typ_or_def idmap) (ty,def) in
144+
List.rev_map f gt.goal_hyps,
146145
Typ("?"^to_string int gt.goal_meta.meta_key,
147146
to_string term gt.goal_type)
148147
| Unif(c,t,u) ->
149-
let ctx_elt (v,ty,def) =
150-
to_string var v,
151-
match def with
152-
| None -> to_string term (Eval.snf_beta ty)
153-
| Some d -> ""^to_string term d
154-
in
155-
List.rev_map ctx_elt c,
148+
let f (v,ty,def) =
149+
to_string var v, to_string (typ_or_def idmap) (ty,def) in
150+
List.rev_map f c,
156151
Unif(to_string term t^""^to_string term u)
157152

158153
(** [add_goals_of_problem p gs] extends the list of goals [gs] with the

0 commit comments

Comments
 (0)