]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_notation/cicNotationEnv.ml
snapshot (added typed environment in 2 -> 1 conversion)
[helm.git] / helm / ocaml / cic_notation / cicNotationEnv.ml
index 13920157ec8c9ddee9313c69758e4e8877331616..b6ae4e6beeed373ec00f7aaac2cb9c62c6674371 100644 (file)
@@ -72,3 +72,31 @@ let list_binding_of_name (n, ty) = (n, (ListType ty, ListValue []))
 let opt_declaration (n, ty) = (n, OptType ty)
 let list_declaration (n, ty) = (n, ListType ty)
 
+let declaration_of_var = function
+  | NumVar s -> s, NumType
+  | IdentVar s -> s, StringType
+  | TermVar s -> s, TermType
+  | _ -> assert false
+
+let value_of_term = function
+  | Num (s, _) -> NumValue s
+  | Ident (s, None) -> StringValue s
+  | t -> TermValue t
+
+let term_of_value = function
+  | NumValue s -> Num (s, 0)
+  | StringValue s -> Ident (s, None)
+  | TermValue t -> t
+  | _ -> assert false (* TO BE UNDERSTOOD *)
+
+let rec well_typed ty value =
+  match ty, value with
+  | TermType, TermValue _
+  | StringType, StringValue _
+  | OptType _, OptValue None
+  | NumType, NumValue _ -> true
+  | OptType ty', OptValue (Some value') -> well_typed ty' value'
+  | ListType ty', ListValue vl ->
+      List.for_all (fun value' -> well_typed ty' value') vl
+  | _ -> false
+