(* Author: Pascal Stoop, ETH Zurich Author: Andreas Lochbihler, Digital Asset *)
section‹Lazy types in generated code›
theory Code_Lazy imports Case_Converter
keywords "code_lazy_type" "activate_lazy_type" "deactivate_lazy_type" "activate_lazy_types" "deactivate_lazy_types" "print_lazy_types" :: thy_decl begin
text‹ This theory and the CodeLazy tool described in 🍋‹"LochbihlerStoop2018"›. It hooks into Isabelle's code generator such that the generated code evaluates a user-specified set of type constructors lazily, even in target languages with eager evaluation. The lazy type must be algebraic, i.e., values must be built from constructors and a corresponding case operator decomposes them. Every datatype and codatatype is algebraic and thus eligible for lazification. ›
subsection‹The type ‹lazy›\›
typedef 'a lazy = "UNIV :: 'a set" ..
setup_lifting type_definition_lazy
lift_definition delay :: "(unit ==> 'a) ==> 'a lazy"is"λf. f ()" .
lift_definition force :: "'a lazy ==> 'a"is"λx. x" .
code_datatype delay lemma force_delay [code]: "force (delay f) = f ()"by transfer (rule refl) lemma delay_force: "delay (λ_. force s) = s"by transfer (rule refl)
lemma term_of_lazy_code [code]: "Code_Evaluation.term_of x ≡ termify_lazy Code_Evaluation.Const Code_Evaluation.App Code_Evaluation.Abs TYPEREP(unit) (λT U. typerep.Typerep (STR ''fun'') [T, U]) (λT. typerep.Typerep (STR ''Code_Lazy.lazy'') [T]) Code_Evaluation.term_of TYPEREP('a) x (Code_Evaluation.Const (STR '''') (TYPEREP(unit)))" for x :: "'a :: {typerep, term_of} lazy" by (rule term_of_anything)
text‹ The implementations of 🍋‹_ lazy›using language primitives cache forced values. Term reconstruction for lazy looks into the lazy value and reconstructs it to the depth it has been evaluated. This is not done for Haskell as we do not know of any portable way to inspect whether a lazy value has been evaluated to or not. ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.