src/Tools/Code/code_haskell.ML
changeset 58397 1c036d6216d3
parent 56826 ba18bd41e510
child 58400 d0d3c30806b4
equal deleted inserted replaced
58396:7b60e4e74430 58397:1c036d6216d3
    88            of SOME (app as ({ sym = Constant const, ... }, _)) =>
    88            of SOME (app as ({ sym = Constant const, ... }, _)) =>
    89                 if is_none (const_syntax const)
    89                 if is_none (const_syntax const)
    90                 then print_case tyvars some_thm vars fxy case_expr
    90                 then print_case tyvars some_thm vars fxy case_expr
    91                 else print_app tyvars some_thm vars fxy app
    91                 else print_app tyvars some_thm vars fxy app
    92             | NONE => print_case tyvars some_thm vars fxy case_expr)
    92             | NONE => print_case tyvars some_thm vars fxy case_expr)
    93     and print_app_expr tyvars some_thm vars ({ sym, dom, range, annotate, ... }, ts) =
    93     and print_app_expr tyvars some_thm vars ({ sym, annotation, ... }, ts) =
    94       let
    94       let
    95         val ty = Library.foldr (op `->) (dom, range)
       
    96         val printed_const =
    95         val printed_const =
    97           if annotate then
    96           case annotation of
    98             brackets [(str o deresolve) sym, str "::", print_typ tyvars NOBR ty]
    97             SOME ty => brackets [(str o deresolve) sym, str "::", print_typ tyvars NOBR ty]
    99           else
    98           | NONE => (str o deresolve) sym
   100             (str o deresolve) sym
       
   101       in 
    99       in 
   102         printed_const :: map (print_term tyvars some_thm vars BR) ts
   100         printed_const :: map (print_term tyvars some_thm vars BR) ts
   103       end
   101       end
   104     and print_app tyvars = gen_print_app (print_app_expr tyvars) (print_term tyvars) const_syntax
   102     and print_app tyvars = gen_print_app (print_app_expr tyvars) (print_term tyvars) const_syntax
   105     and print_bind tyvars some_thm fxy p = gen_print_bind (print_term tyvars) some_thm fxy p
   103     and print_bind tyvars some_thm fxy p = gen_print_bind (print_term tyvars) some_thm fxy p
   239                     str "=",
   237                     str "=",
   240                     print_app tyvars (SOME thm) reserved NOBR (const, [])
   238                     print_app tyvars (SOME thm) reserved NOBR (const, [])
   241                   ]
   239                   ]
   242               | SOME (k, Code_Printer.Complex_printer _) =>
   240               | SOME (k, Code_Printer.Complex_printer _) =>
   243                   let
   241                   let
   244                     val { sym = Constant c, dom, range, ... } = const;
   242                     val { sym = Constant c, dom, ... } = const;
   245                     val (vs, rhs) = (apfst o map) fst
   243                     val (vs, rhs) = (apfst o map) fst
   246                       (Code_Thingol.unfold_abs (Code_Thingol.eta_expand k (const, [])));
   244                       (Code_Thingol.unfold_abs (Code_Thingol.eta_expand k (const, [])));
   247                     val s = if (is_some o const_syntax) c
   245                     val s = if (is_some o const_syntax) c
   248                       then NONE else (SOME o Long_Name.base_name o deresolve_const) c;
   246                       then NONE else (SOME o Long_Name.base_name o deresolve_const) c;
   249                     val vars = reserved
   247                     val vars = reserved
   250                       |> intro_vars (map_filter I (s :: vs));
   248                       |> intro_vars (map_filter I (s :: vs));
   251                     val lhs = IConst { sym = Constant classparam, typargs = [],
   249                     val lhs = IConst { sym = Constant classparam, typargs = [],
   252                       dicts = [], dom = dom, range = range, annotate = false } `$$ map IVar vs;
   250                       dicts = [], dom = dom, annotation = NONE } `$$ map IVar vs;
   253                       (*dictionaries are not relevant at this late stage,
   251                       (*dictionaries are not relevant at this late stage,
   254                         and these consts never need type annotations for disambiguation *)
   252                         and these consts never need type annotations for disambiguation *)
   255                   in
   253                   in
   256                     semicolon [
   254                     semicolon [
   257                       print_term tyvars (SOME thm) vars NOBR lhs,
   255                       print_term tyvars (SOME thm) vars NOBR lhs,