- let metano,context,ty = CicUtil.lookup_meta goal metasenv in
- (* We don't know if [term] is a subterm of [ty] or a subterm of *)
- (* the type of one metavariable. So we replace it everywhere. *)
- (*CSC: Il vero problema e' che non sapendo dove sia il term non *)
- (*CSC: sappiamo neppure quale sia il suo contesto!!!! Insomma, *)
- (*CSC: e' meglio prima cercare il termine e scoprirne il *)
- (*CSC: contesto, poi ridurre e infine rimpiazzare. *)
- let replace context where terms =
- (*CSC: Per il momento se la riduzione fallisce significa solamente che *)
- (*CSC: siamo nel contesto errato. Metto il try, ma che schifo!!!! *)
- (*CSC: Anche perche' cosi' catturo anche quelle del replace che non dovrei *)
- try
- let terms' = List.map (reduction context) terms in
- ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
- ~where:where
- with
- _ -> where
- in
- let find_pattern_for name =
- try Some (snd(List.find (fun (n, pat) -> Cic.Name n = name) hyp_patterns))
- with Not_found -> None
- in
- let ty' =
- match goal_pattern with
- | None -> replace context ty [ty]
- | Some pat ->
- let terms = CicUtil.select ~term:ty ~context:pat in
- let terms = List.map snd terms in
- replace context ty terms
- in
- let context' =
- if hyp_patterns <> [] then
- List.fold_right
- (fun entry context ->
- match entry with
- | Some (name,Cic.Decl term) ->
- (match find_pattern_for name with
- | None -> entry::context
- | Some pat ->
- let terms = CicUtil.select ~term ~context:pat in
- let terms = List.map snd terms in
- let where = replace context term terms in
- let entry = Some (name,Cic.Decl where) in
- entry::context)
- | Some (name,Cic.Def (term, None)) ->
- (match find_pattern_for name with
- | None -> entry::context
- | Some pat ->
- let terms = CicUtil.select ~term ~context:pat in
- let terms = List.map snd terms in
- let where = replace context term terms in
- let entry = Some (name,Cic.Def (where,None)) in
- entry::context)
- | _ -> entry::context
- ) context []