src/HOLCF/ax_ops/thy_ops.ML
changeset 4008 2444085532c6
parent 3771 ede66fb99880
child 4029 22f2d1b17f97
equal deleted inserted replaced
4007:1d6aed7ff375 4008:2444085532c6
   104    | const_name c (Mixfix  x) = Syntax.const_name c x;
   104    | const_name c (Mixfix  x) = Syntax.const_name c x;
   105 end;
   105 end;
   106 
   106 
   107 (* Changing a->b->c res. a*b->c to a=>b=>c. Called by syn_decls. *) 
   107 (* Changing a->b->c res. a*b->c to a=>b=>c. Called by syn_decls. *) 
   108 (*####*)
   108 (*####*)
   109 fun op_to_fun true  sign (Type("->" ,[larg,t]))=
   109 fun op_to_fun true  sign (ty as Type(name ,[larg,t]))= if name = cfun_arrow
   110                                          Type("fun",[larg,op_to_fun true sign t])
   110                   then Type("fun",[larg,op_to_fun true sign t]) else ty
   111   | op_to_fun false sign (Type("->",[args,res])) = let
   111   | op_to_fun false sign (ty as Type(name,[args,res])) = let
   112                 fun otf (Type("*",[larg,rargs])) = Type("fun",[larg,otf rargs])
   112                 fun otf (Type("*",[larg,rargs])) = Type("fun",[larg,otf rargs])
   113                 |   otf t                        = Type("fun",[t,res]);
   113                 |   otf t                        = Type("fun",[t,res]);
   114                 in otf args end
   114                 in if name = cfun_arrow then otf args else ty end
   115   | op_to_fun _     sign t = t(*error("Wrong type for cinfix/cmixfix : "^
   115   | op_to_fun _     sign t = t;
   116                               (Sign.string_of_typ sign t))*);
       
   117 (*####*)
   116 (*####*)
   118 
   117 
   119 (* oldstyle is called by add_ext_axioms(_i) *)
   118 (* oldstyle is called by add_ext_axioms(_i) *)
   120     (* the first part is just copying the homomorphic part of the structures *)
   119     (* the first part is just copying the homomorphic part of the structures *)
   121 fun oldstyle ((name,typ,Mixfix(x))::tl) = 
   120 fun oldstyle ((name,typ,Mixfix(x))::tl) = 
   138       (syn_decls curried sign tl)
   137       (syn_decls curried sign tl)
   139   | syn_decls curried sign ((name,typ,CInfixr(i))::tl) =
   138   | syn_decls curried sign ((name,typ,CInfixr(i))::tl) =
   140      (name,op_to_fun curried sign typ,Mixfix.Infixr(i))::
   139      (name,op_to_fun curried sign typ,Mixfix.Infixr(i))::
   141       (syn_decls curried sign tl)
   140       (syn_decls curried sign tl)
   142   | syn_decls curried sign ((name,typ,CMixfix(x))::tl) =
   141   | syn_decls curried sign ((name,typ,CMixfix(x))::tl) =
   143 (*####
       
   144      ("@"^name,op_to_fun curried sign typ,Mixfix.Mixfix(x))::
       
   145 ####**)
       
   146      (name,op_to_fun curried sign typ,Mixfix.Mixfix(x))::
   142      (name,op_to_fun curried sign typ,Mixfix.Mixfix(x))::
   147 
   143 
   148       (syn_decls curried sign tl)
   144       (syn_decls curried sign tl)
   149   | syn_decls curried sign (_::tl) = syn_decls curried sign tl
   145   | syn_decls curried sign (_::tl) = syn_decls curried sign tl
   150   | syn_decls _ _ [] = [];
   146   | syn_decls _ _ [] = [];
   168       [(mk_appl (Constant "@fapp") 
   164       [(mk_appl (Constant "@fapp") 
   169 	[Constant (mk_internal_name name),Variable "A"]),Variable "B"])
   165 	[Constant (mk_internal_name name),Variable "A"]),Variable "B"])
   170     ::xrules_of true tail
   166     ::xrules_of true tail
   171 (*####*)
   167 (*####*)
   172   | xrules_of true ((name,typ,CMixfix(_))::tail) = 
   168   | xrules_of true ((name,typ,CMixfix(_))::tail) = 
   173         let fun argnames n (Type("->" ,[_,t]))= chr n :: argnames (n+1) t
   169         let fun argnames n (Type(name ,[_,t]))= if name = cfun_arrow then
       
   170 					chr n :: argnames (n+1) t else []
   174             |   argnames _ _ = [];
   171             |   argnames _ _ = [];
   175             val names = argnames (ord"A") typ;
   172             val names = argnames (ord"A") typ;
   176         in if names = [] then [] else 
   173         in if names = [] then [] else 
   177 	    [Syntax.ParsePrintRule (mk_appl (Constant name) (map Variable names),
   174 	    [Syntax.ParsePrintRule (mk_appl (Constant name) (map Variable names),
   178 			 foldl (fn (t,arg) => 
   175 			 foldl (fn (t,arg) => 
   198 		    | itr [a] = a
   195 		    | itr [a] = a
   199 		    | itr (a::l) = f(a, itr l)
   196 		    | itr (a::l) = f(a, itr l)
   200 	      in  itr l end;
   197 	      in  itr l end;
   201 	    fun argnames n (Type("*" ,[_,t]))= chr n :: argnames (n+1) t
   198 	    fun argnames n (Type("*" ,[_,t]))= chr n :: argnames (n+1) t
   202 	    |   argnames n _ = [chr n];
   199 	    |   argnames n _ = [chr n];
   203 	    val vars = map Variable (case typ of (Type("->" ,[t,_])) =>argnames (ord"A") t
   200 	    val vars = map Variable (case typ of (Type(name ,[t,_])) =>
       
   201 			if name = cfun_arrow then argnames (ord"A") t else []
   204 						 | _ => []);
   202 						 | _ => []);
   205         in if vars = [] then [] else 
   203         in if vars = [] then [] else 
   206 	    [Syntax.ParsePrintRule 
   204 	    [Syntax.ParsePrintRule 
   207 	     (mk_appl (Constant name) vars,
   205 	     (mk_appl (Constant name) vars,
   208 	      mk_appl (Constant "@fapp")
   206 	      mk_appl (Constant "@fapp")
   239  fun args_of_tupel (Type("*",[left,right])) = left::(args_of_tupel right)
   237  fun args_of_tupel (Type("*",[left,right])) = left::(args_of_tupel right)
   240    | args_of_tupel T = [T];
   238    | args_of_tupel T = [T];
   241  
   239  
   242  (* A1->...->An->R goes to [(A1,B1),...,(An,Bn)] where Bi=Ai->...->An->R 
   240  (* A1->...->An->R goes to [(A1,B1),...,(An,Bn)] where Bi=Ai->...->An->R 
   243     Bi is the Type of the function that is applied to an Ai type argument *)
   241     Bi is the Type of the function that is applied to an Ai type argument *)
   244  fun args_of_curried (typ as (Type("->",[S,T]))) = 
   242  fun args_of_curried (typ as (Type(name,[S,T]))) = if name = cfun_arrow then
   245       (S,typ) :: args_of_curried T
   243       (S,typ) :: args_of_curried T else []
   246    | args_of_curried _ = [];
   244    | args_of_curried _ = [];
   247 in
   245 in
   248  fun args_of_op true typ = Curried_args(rev(args_of_curried typ))
   246  fun args_of_op true typ = Curried_args(rev(args_of_curried typ))
   249    | args_of_op false (typ as (Type("->",[S,T]))) = 
   247    | args_of_op false (typ as (Type(name,[S,T]))) = if name = cfun_arrow then
   250       Tupeled_args(args_of_tupel S)
   248       Tupeled_args(args_of_tupel S) else Tupeled_args([])
   251    | args_of_op false _ = Tupeled_args([]);
   249    | args_of_op false _ = Tupeled_args([]);
   252 end;
   250 end;
   253 
   251 
   254 (* generates for the type t the type of the fapp constant 
   252 (* generates for the type t the type of the fapp constant 
   255    that will be applied to t *)
   253    that will be applied to t *)
   256 fun mk_fapp_typ (typ as Type("->",argl)) = Type("fun",[typ,Type("fun",argl)]) 
   254 fun mk_fapp_typ (typ as Type(_(*"->"*),argl)) = Type("fun",[typ,Type("fun",argl)]) 
   257   | mk_fapp_typ t = (
   255   | mk_fapp_typ t = (
   258                     error("Internal error:mk_fapp_typ: wrong argument\n"));
   256                     error("Internal error:mk_fapp_typ: wrong argument\n"));
   259                     
   257                     
   260 fun mk_arg_tupel_UU uu_pos [typ] n = 
   258 fun mk_arg_tupel_UU uu_pos [typ] n = 
   261      if n<>uu_pos then Free("x"^(string_of_int n),typ)
   259      if n<>uu_pos then Free("x"^(string_of_int n),typ)