]> matita.cs.unibo.it Git - helm.git/blobdiff - components/acic_content/cicNotationPp.ml
matitac now fails if it tries to insert a new alias
[helm.git] / components / acic_content / cicNotationPp.ml
index efcc25897b4b0301081a03665670c30e0f05fc1a..ff0a09265c0d6b985d4c439b70931f74f0b8eb0a 100644 (file)
@@ -114,13 +114,35 @@ let rec pp_term ?(pp_parens = true) t =
         sprintf "let %s \\def %s in %s" (pp_capture_variable var) (pp_term ~pp_parens:true t1)
           (pp_term ~pp_parens:true t2)
     | Ast.LetRec (kind, definitions, term) ->
-        sprintf "let %s %s in %s"
+        let strip i t =
+          let rec aux i l = function
+             | Ast.Binder (_, var, body) when i > 0 -> aux (pred i) (var :: l) body
+             | body                                 -> List.rev l, body
+          in 
+          aux i [] t
+       in
+       let rec get_guard i = function
+          | []                   -> assert false
+          | [term, _] when i = 1 -> term
+          | _ :: tl              -> get_guard (pred i) tl
+       in
+       let map (var, body, i) =
+           let id, vars, typ, body = match var with
+             | term, Some typ ->
+                let pvars, pbody = strip i typ in
+                let _, bbody = strip i body in
+                term, pvars, pbody, bbody
+             | _              -> assert false
+          in
+          sprintf "%s %s on %s: %s \\def %s" 
+             (pp_term ~pp_parens:false term)
+             (String.concat " " (List.map pp_capture_variable vars))
+             (pp_term ~pp_parens:false (get_guard i vars))
+             (pp_term typ) (pp_term body)
+       in
+       sprintf "let %s %s in %s"
           (match kind with `Inductive -> "rec" | `CoInductive -> "corec")
-          (String.concat " and "
-            (List.map
-              (fun (var, body, _) ->
-                sprintf "%s = %s" (pp_capture_variable var) (pp_term body))
-              definitions))
+          (String.concat " and " (List.map map definitions))
           (pp_term term)
     | Ast.Ident (name, Some []) | Ast.Ident (name, None)
     | Ast.Uri (name, Some []) | Ast.Uri (name, None) ->
@@ -149,6 +171,7 @@ let rec pp_term ?(pp_parens = true) t =
   in
   match pp_parens, t with
     | false, _ 
+    | true, Ast.Implicit
     | true, Ast.Sort _
     | true, Ast.Ident (_, Some []) 
     | true, Ast.Ident (_, None)    -> t_pp
@@ -253,7 +276,7 @@ let pp_params = function
           params)
       
 let pp_flavour = function
-  | `Definition -> "Definition"
+  | `Definition -> "definition"
   | `Fact -> "fact"
   | `Goal -> "goal"
   | `Lemma -> "lemma"
@@ -290,16 +313,16 @@ let pp_obj = function
         in
         fst_typ_pp ^ String.concat "" (List.map pp_type tl))
  | Ast.Theorem (flavour, name, typ, body) ->
-    sprintf "%s %s: %s %s"
+    sprintf "%s %s:\n %s\n%s"
       (pp_flavour flavour)
       name
       (pp_term typ)
       (match body with
       | None -> ""
-      | Some body -> "\\def " ^ pp_term body)
+      | Some body -> "\\def\n " ^ pp_term body)
  | Ast.Record (params,name,ty,fields) ->
-    "record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
-    pp_fields fields ^ "}"
+    "record " ^ name ^ " " ^ pp_params params ^ ": " ^ pp_term ty ^ 
+    " \\def {" ^ pp_fields fields ^ "\n}"
 
 let rec pp_value = function
   | Env.TermValue t -> sprintf "$%s$" (pp_term t)