src/HOL/HOLCF/Tools/fixrec.ML
changeset 63064 2f18172214c8
parent 60801 7664e0916eec
child 63182 b065b4833092
equal deleted inserted replaced
63063:c9605a284fba 63064:2f18172214c8
   332   (lthy : local_theory) =
   332   (lthy : local_theory) =
   333   let
   333   let
   334     val (skips, raw_spec) = ListPair.unzip raw_spec'
   334     val (skips, raw_spec) = ListPair.unzip raw_spec'
   335     val (fixes : ((binding * typ) * mixfix) list,
   335     val (fixes : ((binding * typ) * mixfix) list,
   336          spec : (Attrib.binding * term) list) =
   336          spec : (Attrib.binding * term) list) =
   337           fst (prep_spec raw_fixes raw_spec lthy)
   337           fst (prep_spec raw_fixes (map (rpair []) raw_spec) lthy)
   338     val names = map (Binding.name_of o fst o fst) fixes
   338     val names = map (Binding.name_of o fst o fst) fixes
   339     fun check_head name =
   339     fun check_head name =
   340         member (op =) names name orelse
   340         member (op =) names name orelse
   341         fixrec_err ("Illegal equation head. Expected " ^ commas_quote names)
   341         fixrec_err ("Illegal equation head. Expected " ^ commas_quote names)
   342     val chead_of_spec =
   342     val chead_of_spec =
   375     lthy
   375     lthy
   376   end
   376   end
   377 
   377 
   378 in
   378 in
   379 
   379 
   380 val add_fixrec = gen_fixrec Specification.check_spec
   380 val add_fixrec = gen_fixrec Specification.check_multi_specs
   381 val add_fixrec_cmd = gen_fixrec Specification.read_spec
   381 val add_fixrec_cmd = gen_fixrec Specification.read_multi_specs
   382 
   382 
   383 end (* local *)
   383 end (* local *)
   384 
   384 
   385 
   385 
   386 (*************************************************************************)
   386 (*************************************************************************)
   392     || Parse_Spec.opt_thm_name ":" >> pair false
   392     || Parse_Spec.opt_thm_name ":" >> pair false
   393 
   393 
   394 val spec' : (bool * (Attrib.binding * string)) parser =
   394 val spec' : (bool * (Attrib.binding * string)) parser =
   395   opt_thm_name' -- Parse.prop >> (fn ((a, b), c) => (a, (b, c)))
   395   opt_thm_name' -- Parse.prop >> (fn ((a, b), c) => (a, (b, c)))
   396 
   396 
   397 val alt_specs' : (bool * (Attrib.binding * string)) list parser =
   397 val multi_specs' : (bool * (Attrib.binding * string)) list parser =
   398   let val unexpected = Scan.ahead (Parse.name || @{keyword "["} || @{keyword "("})
   398   let val unexpected = Scan.ahead (Parse.name || @{keyword "["} || @{keyword "("})
   399   in Parse.enum1 "|" (spec' --| Scan.option (unexpected -- Parse.!!! @{keyword "|"})) end
   399   in Parse.enum1 "|" (spec' --| Scan.option (unexpected -- Parse.!!! @{keyword "|"})) end
   400 
   400 
   401 val _ =
   401 val _ =
   402   Outer_Syntax.local_theory @{command_keyword fixrec} "define recursive functions (HOLCF)"
   402   Outer_Syntax.local_theory @{command_keyword fixrec} "define recursive functions (HOLCF)"
   403     (Parse.fixes -- (Parse.where_ |-- Parse.!!! alt_specs')
   403     (Parse.fixes -- (Parse.where_ |-- Parse.!!! multi_specs')
   404       >> (fn (fixes, specs) => add_fixrec_cmd fixes specs))
   404       >> (fn (fixes, specs) => add_fixrec_cmd fixes specs))
   405 
   405 
   406 end
   406 end