(* Author: Pascal Stoop, ETH Zurich
Author: Andreas Lochbihler, Digital Asset *)
section \<open>Lazy types in generated code\<close>
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\<open>
This theoryand the CodeLazy tool described in\<^cite>\<open>"LochbihlerStoop2018"\<close>.
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 datatypeand codatatype is algebraic andthus eligible for lazification. \<close>
subsection \<open>The type \<open>lazy\<close>\<close>
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) (\<lambda>T U. typerep.Typerep (STR ''fun'') [T, U]) (\<lambda>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\<open>
The implementations of \<^typ>\<open>_ lazy\<close> using language primitives cache forced values.
Term reconstruction forlazy looks into the lazyvalueand reconstructs it to the depth it has been evaluated.
This is not donefor Haskell as we do not know of any portable way to inspect whether a lazyvalue
has been evaluated to or not. \<close>
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 ist noch experimentell.