]> matita.cs.unibo.it Git - helm.git/commitdiff
inductive type ident optional in mutcase
authorStefano Zacchiroli <zack@upsilon.cc>
Fri, 13 Feb 2004 13:33:00 +0000 (13:33 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Fri, 13 Feb 2004 13:33:00 +0000 (13:33 +0000)
helm/ocaml/cic_disambiguation/cicTextualParser2.ml
helm/ocaml/cic_disambiguation/disambiguate.ml
helm/ocaml/cic_transformations/acic2Ast.ml
helm/ocaml/cic_transformations/cicAst.ml

index 2bcbb88e8da8a984c5b29c77a4620cd5be539652..0ac43a11e4d0771a6182e22579ac0ab6e2772043 100644 (file)
@@ -179,7 +179,7 @@ EXTEND
             return_term loc (CicAst.LetRec (ind_kind, defs, body))
       | outtyp = OPT [ PAREN "["; typ = term; PAREN "]" -> typ ];
         "match"; t = term;
-        SYMBOL ":"; indty = IDENT;
+        indty_ident = OPT [ SYMBOL ":"; id = IDENT -> id ];
         "with";
         PAREN "[";
         patterns = LIST0 [
@@ -188,7 +188,7 @@ EXTEND
         ] SEP SYMBOL "|";
         PAREN "]" ->
           return_term loc
-            (CicAst.Case (t, indty, outtyp, patterns))
+            (CicAst.Case (t, indty_ident, outtyp, patterns))
       | PAREN "("; t = term; PAREN ")" -> return_term loc t
       ]
     ];
index edc112992121133be7071cb66939920756b6e60d..06f18080d07466aaccba41ca71b3d83599ae4678 100644 (file)
@@ -110,10 +110,23 @@ let interpretate ~context ~env ast =
           do_branch' context args
         in
         let (indtype_uri, indtype_no) =
-          match resolve env (Id indty_ident) () with
-          | Cic.MutInd (uri, tyno, _) -> uri, tyno
-          | Cic.Implicit _ -> raise Try_again
-          | _ -> raise DisambiguateChoices.Invalid_choice
+          match indty_ident with
+          | Some indty_ident ->
+              (match resolve env (Id indty_ident) () with
+              | Cic.MutInd (uri, tyno, _) -> (uri, tyno)
+              | Cic.Implicit _ -> raise Try_again
+              | _ -> raise DisambiguateChoices.Invalid_choice)
+          | None ->
+              let fst_constructor =
+                match branches with
+                | ((head, _), _) :: _ -> head
+                | [] -> raise DisambiguateChoices.Invalid_choice
+              in
+              (match resolve env (Id fst_constructor) () with
+              | Cic.MutConstruct (indtype_uri, indtype_no, _, _) ->
+                  (indtype_uri, indtype_no)
+              | Cic.Implicit _ -> raise Try_again
+              | _ -> raise DisambiguateChoices.Invalid_choice)
         in
         Cic.MutCase (indtype_uri, indtype_no, cic_outtype, cic_term,
           (List.map do_branch branches))
@@ -283,7 +296,8 @@ let domain_of_term ~context ast =
         let branches_dom =
           List.fold_left (fun dom branch -> do_branch branch @ dom) [] branches
         in
-        branches_dom @ outtype_dom @ term_dom @ [ Id indty_ident ]
+        branches_dom @ outtype_dom @ term_dom @
+        (match indty_ident with None -> [] | Some ident -> [ Id ident ])
     | CicAst.LetIn ((var, typ), body, where) ->
         let body_dom = aux loc context body in
         let type_dom = aux_option loc context typ in
index fc6d9553174fbf2521dba05ed7228fe1a79db07b..19b6c4b4bf4161ab4546d2f178fe9e13d2c117be 100644 (file)
@@ -166,7 +166,7 @@ let ast_of_acic ids_to_inner_sorts ids_to_uris acic =
               ((name, capture_variables), rhs))
             constructors patterns
         in
-        idref id (Ast.Case (aux te, name, Some (aux ty), patterns))
+        idref id (Ast.Case (aux te, Some name, Some (aux ty), patterns))
     | Cic.AFix (id, no, funs) -> 
         let defs = 
           List.map
index f5aeb5d840d811704dfcae886cf75a76232d3b48..b992a916c28371a82def85cc21e1ff10eadbf39d 100644 (file)
@@ -97,7 +97,7 @@ type term =
 
   | Appl of term list
   | Binder of binder_kind * capture_variable * term (* kind, name, body *)
-  | Case of term * string * term option * (case_pattern * term) list
+  | Case of term * string option * term option * (case_pattern * term) list
       (* what to match, inductive type, out type, <pattern,action> list *)
   | LetIn of capture_variable * term * term  (* name, body, where *)
   | LetRec of induction_kind * (capture_variable * term * int) list * term