diff --git a/slides.md b/slides.md index 5f90ff6..e23dc57 100644 --- a/slides.md +++ b/slides.md @@ -57,7 +57,7 @@ @@ -68,6 +68,7 @@ * El largo camino a Java 22. * Tipos de datos algebraicos. +* Ejemplos. * Futuro. --- @@ -97,7 +98,7 @@ * Una nueva vida para `switch`. * Expresión. - @@ -229,19 +230,19 @@ * AKA ADTs (algebraic data types). * Viene de las matemáticas. -* Productos y sumas de tipos. - `a + b` `a * b` -* Cardinalidad. * Recursivo. --- # ADTs +* Productos y sumas de tipos. + `a + b` `a * b` +* Cardinalidad. * Tienen propiedades algebraicas: * Identidad: `a + 0 <=> a` `a * 1 <=> a` - * Distributiva: + * Distributiva: `(a * b) + (a * c) <=> a * (b + c)` * Conmutativa: `a * b <=> b * a` `a + b <=> b + a` @@ -259,29 +260,6 @@ --- -# ADTs: Identidad Suma - -```java -sealed interface Sum { - record A(String value) implements Sum {} - // uninstantiable, similar to Void type - final class B implements Sum { - private B() {} - } -} -``` ---- - -# ADTs: Identidad Producto - -```java -// just one value -enum Unit { VALUE } -record Product(String value, Unit unit) {} -``` - ---- - # ADTs: List ```java @@ -356,7 +334,7 @@ MovieResponse create(Movie movie); } -sealed interface MovieResponse permits MovieCreated, MovieResponse {} +sealed interface MovieResponse permits MovieCreated, MovieError {} record MovieCreated(UUID id) implements MovieResponse {} ``` @@ -432,7 +410,7 @@ --- -# Member patterns +# Static patterns ```java var result = switch (optional) { @@ -448,6 +426,19 @@ --- +# Constant patterns + +```java +var result = switch (optional) { + case Point(0, var y) -> process(y); + case Point(var x, var y) -> process(x, y); +}; +``` + +* ??? + +--- + # ¿Qué falta todavía? * Tail recursion. @@ -520,9 +511,9 @@ a + b - exponential types are functions - tree of products and sums - - distributibity + - distributibity (a * b) + (a * c) <=> a * (b + c) - - commutatibity + - commutatibity a * b <=> b * a a + b <=> b + a - identity: @@ -539,5 +530,4 @@ - content - confirm expectations - links to follow - --> ---> \ No newline at end of file + --> \ No newline at end of file