src/Tools/Code/code_haskell.ML
changeset 37449 034ebe92f090
parent 37447 ad3e04f289b6
child 37651 62fc16341922
equal deleted inserted replaced
37448:3bd4b3809bee 37449:034ebe92f090
    73           (case Code_Thingol.unfold_const_app t0
    73           (case Code_Thingol.unfold_const_app t0
    74            of SOME (c_ts as ((c, _), _)) => if is_none (syntax_const c)
    74            of SOME (c_ts as ((c, _), _)) => if is_none (syntax_const c)
    75                 then print_case tyvars some_thm vars fxy cases
    75                 then print_case tyvars some_thm vars fxy cases
    76                 else print_app tyvars some_thm vars fxy c_ts
    76                 else print_app tyvars some_thm vars fxy c_ts
    77             | NONE => print_case tyvars some_thm vars fxy cases)
    77             | NONE => print_case tyvars some_thm vars fxy cases)
    78     and print_app_expr tyvars some_thm vars ((c, (_, tys)), ts) = case contr_classparam_typs c
    78     and print_app_expr tyvars some_thm vars ((c, (_, function_typs)), ts) = case contr_classparam_typs c
    79      of [] => (str o deresolve) c :: map (print_term tyvars some_thm vars BR) ts
    79      of [] => (str o deresolve) c :: map (print_term tyvars some_thm vars BR) ts
    80       | fingerprint => let
    80       | fingerprint => let
    81           val ts_fingerprint = ts ~~ take (length ts) fingerprint;
    81           val ts_fingerprint = ts ~~ take (length ts) fingerprint;
    82           val needs_annotation = forall (fn (_, NONE) => true | (t, SOME _) =>
    82           val needs_annotation = forall (fn (_, NONE) => true | (t, SOME _) =>
    83             (not o Code_Thingol.locally_monomorphic) t) ts_fingerprint;
    83             (not o Code_Thingol.locally_monomorphic) t) ts_fingerprint;
    84           fun print_term_anno (t, NONE) _ = print_term tyvars some_thm vars BR t
    84           fun print_term_anno (t, NONE) _ = print_term tyvars some_thm vars BR t
    85             | print_term_anno (t, SOME _) ty =
    85             | print_term_anno (t, SOME _) ty =
    86                 brackets [print_term tyvars some_thm vars NOBR t, str "::", print_typ tyvars NOBR ty];
    86                 brackets [print_term tyvars some_thm vars NOBR t, str "::", print_typ tyvars NOBR ty];
    87         in
    87         in
    88           if needs_annotation then
    88           if needs_annotation then
    89             (str o deresolve) c :: map2 print_term_anno ts_fingerprint (take (length ts) tys)
    89             (str o deresolve) c :: map2 print_term_anno ts_fingerprint (take (length ts) function_typs)
    90           else (str o deresolve) c :: map (print_term tyvars some_thm vars BR) ts
    90           else (str o deresolve) c :: map (print_term tyvars some_thm vars BR) ts
    91         end
    91         end
    92     and print_app tyvars = gen_print_app (print_app_expr tyvars) (print_term tyvars) syntax_const
    92     and print_app tyvars = gen_print_app (print_app_expr tyvars) (print_term tyvars) syntax_const
    93     and print_bind tyvars some_thm fxy p = gen_print_bind (print_term tyvars) some_thm fxy p
    93     and print_bind tyvars some_thm fxy p = gen_print_bind (print_term tyvars) some_thm fxy p
    94     and print_case tyvars some_thm vars fxy (cases as ((_, [_]), _)) =
    94     and print_case tyvars some_thm vars fxy (cases as ((_, [_]), _)) =
   161             semicolon [
   161             semicolon [
   162               str "data",
   162               str "data",
   163               print_typdecl tyvars (vs, (deresolve_base name, map (ITyVar o fst) vs))
   163               print_typdecl tyvars (vs, (deresolve_base name, map (ITyVar o fst) vs))
   164             ]
   164             ]
   165           end
   165           end
   166       | print_stmt (name, Code_Thingol.Datatype (_, (vs, [(co, [ty])]))) =
   166       | print_stmt (name, Code_Thingol.Datatype (_, (vs, [((co, _), [ty])]))) =
   167           let
   167           let
   168             val tyvars = intro_vars (map fst vs) reserved;
   168             val tyvars = intro_vars (map fst vs) reserved;
   169           in
   169           in
   170             semicolon (
   170             semicolon (
   171               str "newtype"
   171               str "newtype"
   177             )
   177             )
   178           end
   178           end
   179       | print_stmt (name, Code_Thingol.Datatype (_, (vs, co :: cos))) =
   179       | print_stmt (name, Code_Thingol.Datatype (_, (vs, co :: cos))) =
   180           let
   180           let
   181             val tyvars = intro_vars (map fst vs) reserved;
   181             val tyvars = intro_vars (map fst vs) reserved;
   182             fun print_co (co, tys) =
   182             fun print_co ((co, _), tys) =
   183               concat (
   183               concat (
   184                 (str o deresolve_base) co
   184                 (str o deresolve_base) co
   185                 :: map (print_typ tyvars BR) tys
   185                 :: map (print_typ tyvars BR) tys
   186               )
   186               )
   187           in
   187           in
   212                 str " where {"
   212                 str " where {"
   213               ],
   213               ],
   214               str "};"
   214               str "};"
   215             ) (map print_classparam classparams)
   215             ) (map print_classparam classparams)
   216           end
   216           end
   217       | print_stmt (_, Code_Thingol.Classinst ((class, (tyco, vs)), (_, classparam_instances))) =
   217       | print_stmt (_, Code_Thingol.Classinst ((class, (tyco, vs)), (_, (classparam_instances, _)))) =
   218           let
   218           let
   219             val tyvars = intro_vars (map fst vs) reserved;
   219             val tyvars = intro_vars (map fst vs) reserved;
   220             fun print_classparam_instance ((classparam, const), (thm, _)) = case syntax_const classparam
   220             fun print_classparam_instance ((classparam, const), (thm, _)) = case syntax_const classparam
   221              of NONE => semicolon [
   221              of NONE => semicolon [
   222                     (str o deresolve_base) classparam,
   222                     (str o deresolve_base) classparam,