src/HOLCF/domain/syntax.ML
changeset 15574 b1d1b5bfc464
parent 15570 8d8c70b41bab
child 16224 57094b83774e
equal deleted inserted replaced
15573:cf53c2dcf440 15574:b1d1b5bfc464
    20   fun opt_lazy (lazy,_,t) = if lazy then mk_uT t else t
    20   fun opt_lazy (lazy,_,t) = if lazy then mk_uT t else t
    21   fun prod     (_,_,args) = if args = [] then oneT
    21   fun prod     (_,_,args) = if args = [] then oneT
    22 			    else foldr' mk_sprodT (map opt_lazy args);
    22 			    else foldr' mk_sprodT (map opt_lazy args);
    23   fun freetvar s = let val tvar = mk_TFree s in
    23   fun freetvar s = let val tvar = mk_TFree s in
    24 		   if tvar mem typevars then freetvar ("t"^s) else tvar end;
    24 		   if tvar mem typevars then freetvar ("t"^s) else tvar end;
    25   fun when_type (_   ,_,args) = Library.foldr (op ->>) (map third args,freetvar "t");
    25   fun when_type (_   ,_,args) = foldr (op ->>) (freetvar "t") (map third args);
    26 in
    26 in
    27   val dtype  = Type(dname,typevars);
    27   val dtype  = Type(dname,typevars);
    28   val dtype2 = foldr' mk_ssumT (map prod cons');
    28   val dtype2 = foldr' mk_ssumT (map prod cons');
    29   val dnam = Sign.base_name dname;
    29   val dnam = Sign.base_name dname;
    30   val const_rep  = (dnam^"_rep" ,              dtype  ->> dtype2, NoSyn);
    30   val const_rep  = (dnam^"_rep" ,              dtype  ->> dtype2, NoSyn);
    31   val const_abs  = (dnam^"_abs" ,              dtype2 ->> dtype , NoSyn);
    31   val const_abs  = (dnam^"_abs" ,              dtype2 ->> dtype , NoSyn);
    32   val const_when = (dnam^"_when",Library.foldr (op ->>) ((map when_type cons'),
    32   val const_when = (dnam^"_when",foldr (op ->>) (dtype ->> freetvar "t") (map when_type cons'), NoSyn);
    33 					        dtype ->> freetvar "t"), NoSyn);
       
    34   val const_copy = (dnam^"_copy", dtypeprod ->> dtype  ->> dtype , NoSyn);
    33   val const_copy = (dnam^"_copy", dtypeprod ->> dtype  ->> dtype , NoSyn);
    35 end;
    34 end;
    36 
    35 
    37 (* ----- constants concerning constructors, discriminators, and selectors --- *)
    36 (* ----- constants concerning constructors, discriminators, and selectors --- *)
    38 
    37 
    40   val escape = let
    39   val escape = let
    41 	fun esc (c::cs) = if c mem ["'","_","(",")","/"] then "'"::c::esc cs
    40 	fun esc (c::cs) = if c mem ["'","_","(",")","/"] then "'"::c::esc cs
    42 							 else      c::esc cs
    41 							 else      c::esc cs
    43 	|   esc []      = []
    42 	|   esc []      = []
    44 	in implode o esc o Symbol.explode end;
    43 	in implode o esc o Symbol.explode end;
    45   fun con (name,s,args) = (name,Library.foldr (op ->>) (map third args,dtype),s);
    44   fun con (name,s,args) = (name,foldr (op ->>) dtype (map third args),s);
    46   fun dis (con ,s,_   ) = (dis_name_ con, dtype->>trT,
    45   fun dis (con ,s,_   ) = (dis_name_ con, dtype->>trT,
    47 			   Mixfix(escape ("is_" ^ con), [], Syntax.max_pri));
    46 			   Mixfix(escape ("is_" ^ con), [], Syntax.max_pri));
    48 			(* stricly speaking, these constants have one argument,
    47 			(* stricly speaking, these constants have one argument,
    49 			   but the mixfix (without arguments) is introduced only
    48 			   but the mixfix (without arguments) is introduced only
    50 			   to generate parse rules for non-alphanumeric names*)
    49 			   to generate parse rules for non-alphanumeric names*)