src/HOL/Tools/Quotient/quotient_def.ML
changeset 43663 e8c80bbc0c5d
parent 43608 294570668f25
child 45279 89a17197cb98
--- a/src/HOL/Tools/Quotient/quotient_def.ML	Mon Jul 04 22:25:33 2011 +0200
+++ b/src/HOL/Tools/Quotient/quotient_def.ML	Tue Jul 05 09:54:39 2011 +0200
@@ -46,8 +46,9 @@
 fun gen_quotient_def prep_vars prep_term (raw_var, (attr, (lhs_raw, rhs_raw))) lthy =
   let
     val (vars, ctxt) = prep_vars (the_list raw_var) lthy
-    val lhs = prep_term ctxt lhs_raw
-    val rhs = prep_term ctxt rhs_raw
+    val T_opt = (case vars of [(_, SOME T, _)] => SOME T | _ => NONE)
+    val lhs = prep_term T_opt ctxt lhs_raw
+    val rhs = prep_term NONE ctxt rhs_raw
 
     val (lhs_str, lhs_ty) = dest_Free lhs handle TERM _ => error "Constant already defined."
     val _ = if null (strip_abs_vars rhs) then () else error "The definiens cannot be an abstraction"
@@ -80,8 +81,12 @@
     (qconst_data, lthy'')
   end
 
-val quotient_def = gen_quotient_def Proof_Context.cert_vars Syntax.check_term
-val quotdef_cmd = gen_quotient_def Proof_Context.read_vars Syntax.read_term
+fun check_term' cnstr ctxt =
+  Syntax.check_term ctxt o (case cnstr of SOME T => Type.constraint T | _ => I)
+fun read_term' cnstr ctxt = check_term' cnstr ctxt o tap (writeln o @{make_string}) o Syntax.parse_term ctxt
+
+val quotient_def = gen_quotient_def Proof_Context.cert_vars check_term'
+val quotdef_cmd = gen_quotient_def Proof_Context.read_vars read_term'
 
 
 (* a wrapper for automatically lifting a raw constant *)