|
12 | 12 | font-family: 'Yanone Kaffeesatz';
|
13 | 13 | font-weight: normal;
|
14 | 14 | }
|
15 |
| - small .MathJax_Display { |
| 15 | + small .MathJax_Display, small .remark-code { |
16 | 16 | font-size: small;
|
17 | 17 | }
|
18 | 18 | .remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
|
|
31 | 31 |
|
32 | 32 | # Index
|
33 | 33 |
|
34 |
| -1. **Algebraic Data Types**. |
35 |
| -1. **Free Algebras**. |
36 |
| -1. **Equational Reasoning** at the program level. |
| 34 | +1. **Data Types**. |
| 35 | + * Algebraic data types. |
| 36 | + * Generalized algebraic data types. |
| 37 | + * Sum and product data types. |
| 38 | +1. **Algebras**. |
| 39 | + * Boolean Algebra |
| 40 | + * Free Algebra |
| 41 | +1. ~~**Equational Reasoning** at the program level.~~ |
37 | 42 |
|
38 | 43 | ---
|
39 | 44 |
|
|
54 | 59 |
|
55 | 60 | # Algebraic Data Types
|
56 | 61 |
|
57 |
| -An algebraic data type is a missnomer. |
58 |
| - |
59 | 62 | An algebraic data type is not *just* a data type, it's a data type *plus* an
|
60 | 63 | algebra.
|
61 | 64 |
|
|
85 | 88 | ```
|
86 | 89 |
|
87 | 90 | In the context of scala, case classes come with their own `apply` and `unapply`
|
88 |
| -for a pattern matching algebra. |
| 91 | +for a structural (pattern matching) algebra. |
89 | 92 |
|
90 | 93 | <small>
|
91 | 94 | (If you look at regular expressions in pattern matching you might be pleasently
|
|
94 | 97 |
|
95 | 98 | ---
|
96 | 99 |
|
| 100 | +# Generalized Algebraic Data Type |
| 101 | + |
| 102 | +As long as you trust inheritance |
| 103 | + |
| 104 | +<small> |
| 105 | +```tut |
| 106 | +sealed abstract trait Lam[A] {def a: A} |
| 107 | +case class Lift[A](a: A) extends Lam[A] |
| 108 | +case class Tup[A, B](_a: A, b: B) extends Lam[(A, B)] {def a = (_a, b)} |
| 109 | +case class Lamda[A, B](f: Lam[A] => Lam[B]) extends Lam[A => B] { |
| 110 | + def a = { _a => f(Lift(_a)).a } |
| 111 | +} |
| 112 | +case class App[A, B](f: Lam[A => B], _a: Lam[A]) extends Lam[B] {def a = f.a(_a.a)} |
| 113 | +case class Fix[A](f: Lam[A => A]) extends Lam[A] { |
| 114 | + def a = Fix(Lift(_a => f.a(_a))).a |
| 115 | +} |
| 116 | +``` |
| 117 | +</small> |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +# Sum Types and Product Types |
| 122 | + |
| 123 | +Structurally: |
| 124 | + |
| 125 | +```tut |
| 126 | +type Sum[A] = Lam[A] // Lift ∨ Tup ∨ Lambda ∨ App ∨ Fix |
| 127 | +type Prod[A, B] = Tup[A, B] // A ∧ B |
| 128 | +type Prod2[A, B] = (Lam[A], Lam[B]) // Lam[A] ∧ Lam[B] |
| 129 | +``` |
| 130 | + |
| 131 | +<small> |
| 132 | + [Sum and Product types as encoded by Shapeless 2.1.0](https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.1.0) |
| 133 | +</small> |
| 134 | + |
| 135 | +--- |
| 136 | + |
97 | 137 | # Boolean Algebra
|
98 | 138 |
|
99 | 139 | Boolean algebra satisfies many of the same laws as arithmetic when one
|
|
143 | 183 |
|
144 | 184 | * [Algebraic Data Types](http://tpolecat.github.io/presentations/algebraic_types.html)
|
145 | 185 | by Rob Norris (@tpolecat)
|
| 186 | +* [Shapeless 2.1.0 Feature Overview](https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.1.0) |
| 187 | +* [I am not a monad, I am a free algebra](http://biosimilarity.blogspot.com/2011/08/i-am-not-monad-i-am-free-algebra-pt-1.html) |
146 | 188 | * [Sweeping crap APIs under the rug](http://tpolecat.github.io/presentations/lambdaconf14.html)
|
147 | 189 | by Rob Norris (@tpolecat)
|
148 | 190 |
|
|
0 commit comments