src/Tools/code/code_haskell.ML
changeset 28064 d4a6460c53d1
parent 28054 2b84d34c5d02
child 28145 af3923ed4786
equal deleted inserted replaced
28063:3533485fc7b8 28064:d4a6460c53d1
   406       (map (uncurry pr_module) includes
   406       (map (uncurry pr_module) includes
   407         @ map serialize_module (Symtab.dest hs_program))
   407         @ map serialize_module (Symtab.dest hs_program))
   408       destination
   408       destination
   409   end;
   409   end;
   410 
   410 
       
   411 val literals = let
       
   412   fun char_haskell c =
       
   413     let
       
   414       val s = ML_Syntax.print_char c;
       
   415     in if s = "'" then "\\'" else s end;
       
   416 in Literals {
       
   417   literal_char = enclose "'" "'" o char_haskell,
       
   418   literal_string = quote o translate_string char_haskell,
       
   419   literal_numeral = fn unbounded => fn k => if k >= 0 then string_of_int k
       
   420     else enclose "(" ")" (signed_string_of_int k),
       
   421   literal_list = Pretty.enum "," "[" "]",
       
   422   infix_cons = (5, ":")
       
   423 } end;
       
   424 
   411 
   425 
   412 (** optional monad syntax **)
   426 (** optional monad syntax **)
   413 
   427 
   414 fun implode_monad c_bind t =
   428 fun implode_monad c_bind t =
   415   let
   429   let
   472     >> (fn ((raw_run, raw_bind), target) => Toplevel.theory 
   486     >> (fn ((raw_run, raw_bind), target) => Toplevel.theory 
   473           (add_monad target raw_run raw_bind))
   487           (add_monad target raw_run raw_bind))
   474   );
   488   );
   475 
   489 
   476 val setup =
   490 val setup =
   477   Code_Target.add_target (target, isar_seri_haskell)
   491   Code_Target.add_target (target, (isar_seri_haskell, literals))
   478   #> Code_Target.add_syntax_tyco target "fun" (SOME (2, fn pr_typ => fn fxy => fn [ty1, ty2] =>
   492   #> Code_Target.add_syntax_tyco target "fun" (SOME (2, fn pr_typ => fn fxy => fn [ty1, ty2] =>
   479       brackify_infix (1, R) fxy [
   493       brackify_infix (1, R) fxy [
   480         pr_typ (INFX (1, X)) ty1,
   494         pr_typ (INFX (1, X)) ty1,
   481         str "->",
   495         str "->",
   482         pr_typ (INFX (1, R)) ty2
   496         pr_typ (INFX (1, R)) ty2