Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Archive-of-Formal-Proofs/thys/Optics/     Datei vom 29.4.2026 mit Größe 1 kB image not shown  

Quelle  Prisms_Examples.thy

  Sprache: Isabelle
 

section  Examples using Prisms

theory Prisms_Examples
  imports Prisms
begin

text  We demonstrate prisms for manipulating an algebraic data type with three constructors .

datatype D = A int | B string | C bool

fun fromA :: "D ==> int option" where "fromA (A x) = Some x" | "fromA _ = None"
fun fromB :: "D ==> string option" where "fromB (B x) = Some x" | "fromB _ = None"
fun fromC :: "D ==> bool option" where "fromC (C x) = Some x" | "fromC _ = None"

text  We create a prism for each of the three constructors.

definition A_prism :: "int ==>\<triangle> D" ("A\<triangle>"where
[lens_defs]: "A\<triangle> = ( prism_match = fromA, prism_build = A )"

definition B_prism :: "string ==>\<triangle> D" ("B\<triangle>"where
[lens_defs]: "B\<triangle> = ( prism_match = fromB, prism_build = B )"

definition C_prism :: "bool ==>\<triangle> D" ("C\<triangle>"where
[lens_defs]: "C\<triangle> = ( prism_match = fromC, prism_build = C )"

text  All three are well-behaved.

lemma A_wb_prism [simp]: "wb_prism A\<triangle>"
  using fromA.elims by (unfold_locales, auto simp add: lens_defs)

lemma B_wb_prism [simp]: "wb_prism B\<triangle>"
  using fromB.elims by (unfold_locales, auto simp add: lens_defs)

lemma C_wb_prism [simp]: "wb_prism C\<triangle>"
  using fromC.elims by (unfold_locales, auto simp add: lens_defs)

text  All three prisms are codependent with each other.

lemma D_codeps: "A\<triangle> B\<triangle>" "A\<triangle> C\<triangle>" "B\<triangle> C\<triangle>"
  by (rule prism_diff_intro, simp add: lens_defs)+

end

Messung V0.5 in Prozent
C=89 H=100 G=94

¤ Dauer der Verarbeitung: 0.1 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen



NIST Cobol Testsuite



Haftungshinweis

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.