src/HOL/HOLCF/Tools/Domain/domain_constructors.ML
changeset 46125 00cd193a48dc
parent 45654 cf10bde35973
child 46490 e4863ab5e09b
equal deleted inserted replaced
46124:3ee75fe01986 46125:00cd193a48dc
   450       fun argvars n args = map_index (argvar n) args
   450       fun argvars n args = map_index (argvar n) args
   451       fun app s (l, r) = Ast.mk_appl (Ast.Constant s) [l, r]
   451       fun app s (l, r) = Ast.mk_appl (Ast.Constant s) [l, r]
   452       val cabs = app "_cabs"
   452       val cabs = app "_cabs"
   453       val capp = app @{const_syntax Rep_cfun}
   453       val capp = app @{const_syntax Rep_cfun}
   454       val capps = Library.foldl capp
   454       val capps = Library.foldl capp
   455       fun con1 authentic n (con,args) =
   455       fun con1 authentic n (con, args) =
   456           Library.foldl capp (c_ast authentic con, argvars n args)
   456           Library.foldl capp (c_ast authentic con, argvars n args)
   457       fun case1 authentic (n, c) =
   457       fun con1_constraint authentic n (con, args) =
   458           app "_case1" (Ast.strip_positions (con1 authentic n c), expvar n)
   458           Library.foldl capp
       
   459             (Ast.Appl
       
   460               [Ast.Constant @{syntax_const "_constrain"}, c_ast authentic con,
       
   461                 Ast.Variable ("'a" ^ string_of_int n)],
       
   462              argvars n args)
       
   463       fun case1 constraint authentic (n, c) =
       
   464         app @{syntax_const "_case1"}
       
   465           ((if constraint then con1_constraint else con1) authentic n c, expvar n)
   459       fun arg1 (n, (_, args)) = List.foldr cabs (expvar n) (argvars n args)
   466       fun arg1 (n, (_, args)) = List.foldr cabs (expvar n) (argvars n args)
   460       fun when1 n (m, c) = if n = m then arg1 (n, c) else Ast.Constant @{const_syntax bottom}
   467       fun when1 n (m, c) = if n = m then arg1 (n, c) else Ast.Constant @{const_syntax bottom}
   461       val case_constant = Ast.Constant (syntax (case_const dummyT))
   468       val case_constant = Ast.Constant (syntax (case_const dummyT))
   462       fun case_trans authentic =
   469       fun case_trans constraint authentic =
   463         (if authentic then Syntax.Parse_Print_Rule else Syntax.Parse_Rule)
       
   464           (app "_case_syntax"
   470           (app "_case_syntax"
   465             (Ast.Variable "x",
   471             (Ast.Variable "x",
   466              foldr1 (app "_case2") (map_index (case1 authentic) spec)),
   472              foldr1 (app @{syntax_const "_case2"}) (map_index (case1 constraint authentic) spec)),
   467            capp (capps (case_constant, map_index arg1 spec), Ast.Variable "x"))
   473            capp (capps (case_constant, map_index arg1 spec), Ast.Variable "x"))
   468       fun one_abscon_trans authentic (n, c) =
   474       fun one_abscon_trans authentic (n, c) =
   469         (if authentic then Syntax.Parse_Print_Rule else Syntax.Parse_Rule)
   475           (if authentic then Syntax.Parse_Print_Rule else Syntax.Parse_Rule)
   470           (cabs (con1 authentic n c, expvar n),
   476             (cabs (con1 authentic n c, expvar n),
   471            capps (case_constant, map_index (when1 n) spec))
   477              capps (case_constant, map_index (when1 n) spec))
   472       fun abscon_trans authentic =
   478       fun abscon_trans authentic =
   473           map_index (one_abscon_trans authentic) spec
   479           map_index (one_abscon_trans authentic) spec
   474       val trans_rules : Ast.ast Syntax.trrule list =
   480       val trans_rules : Ast.ast Syntax.trrule list =
   475           case_trans false :: case_trans true ::
   481           Syntax.Parse_Print_Rule (case_trans false true) ::
       
   482           Syntax.Parse_Rule (case_trans false false) ::
       
   483           Syntax.Parse_Rule (case_trans true false) ::
   476           abscon_trans false @ abscon_trans true
   484           abscon_trans false @ abscon_trans true
   477     in
   485     in
   478       val thy = Sign.add_trrules trans_rules thy
   486       val thy = Sign.add_trrules trans_rules thy
   479     end
   487     end
   480 
   488