src/Tools/Code/code_haskell.ML
changeset 44793 fddb09e6f84d
parent 44792 26b19918e670
child 44852 8ac91e7b6024
equal deleted inserted replaced
44792:26b19918e670 44793:fddb09e6f84d
    23 
    23 
    24 
    24 
    25 (** Haskell serializer **)
    25 (** Haskell serializer **)
    26 
    26 
    27 fun print_haskell_stmt labelled_name class_syntax tyco_syntax const_syntax
    27 fun print_haskell_stmt labelled_name class_syntax tyco_syntax const_syntax
    28     reserved deresolve contr_classparam_typs deriving_show =
    28     reserved deresolve deriving_show =
    29   let
    29   let
    30     fun class_name class = case class_syntax class
    30     fun class_name class = case class_syntax class
    31      of NONE => deresolve class
    31      of NONE => deresolve class
    32       | SOME class => class;
    32       | SOME class => class;
    33     fun print_typcontext tyvars vs = case maps (fn (v, sort) => map (pair v) sort) vs
    33     fun print_typcontext tyvars vs = case maps (fn (v, sort) => map (pair v) sort) vs
   296     val reserved = fold (insert (op =) o fst) includes reserved_syms;
   296     val reserved = fold (insert (op =) o fst) includes reserved_syms;
   297     val { deresolver, flat_program = haskell_program } = haskell_program_of_program
   297     val { deresolver, flat_program = haskell_program } = haskell_program_of_program
   298       labelled_name module_alias module_prefix (Name.make_context reserved) program;
   298       labelled_name module_alias module_prefix (Name.make_context reserved) program;
   299 
   299 
   300     (* print statements *)
   300     (* print statements *)
   301     val contr_classparam_typs = Code_Thingol.contr_classparam_typs program;
       
   302     fun deriving_show tyco =
   301     fun deriving_show tyco =
   303       let
   302       let
   304         fun deriv _ "fun" = false
   303         fun deriv _ "fun" = false
   305           | deriv tycos tyco = not (tyco = Code_Thingol.fun_tyco)
   304           | deriv tycos tyco = not (tyco = Code_Thingol.fun_tyco)
   306               andalso (member (op =) tycos tyco
   305               andalso (member (op =) tycos tyco
   312               andalso forall (deriv' tycos) tys
   311               andalso forall (deriv' tycos) tys
   313           | deriv' _ (ITyVar _) = true
   312           | deriv' _ (ITyVar _) = true
   314       in deriv [] tyco end;
   313       in deriv [] tyco end;
   315     fun print_stmt deresolve = print_haskell_stmt labelled_name
   314     fun print_stmt deresolve = print_haskell_stmt labelled_name
   316       class_syntax tyco_syntax const_syntax (make_vars reserved)
   315       class_syntax tyco_syntax const_syntax (make_vars reserved)
   317       deresolve contr_classparam_typs
   316       deresolve
   318       (if string_classes then deriving_show else K false);
   317       (if string_classes then deriving_show else K false);
   319 
   318 
   320     (* print modules *)
   319     (* print modules *)
   321     val import_includes_ps =
   320     val import_includes_ps =
   322       map (fn (name, _) => str ("import qualified " ^ name ^ ";")) includes;
   321       map (fn (name, _) => str ("import qualified " ^ name ^ ";")) includes;