Skip to content

Commit e059fac

Browse files
committed
Free Algebras
1 parent 647cb4a commit e059fac

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

algebraic-data-types/src/main/tut/index.html

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
# Generalized Algebraic Data Type
101101

102-
As long as you trust inheritance
102+
As long as you trust inheritance and dynamic dispatch you would probably also trust:
103103

104104
<small>
105105
```tut
@@ -116,11 +116,13 @@
116116
```
117117
</small>
118118

119+
<small>Paul Chiusano (scalaz-stream) has documented his attempts [here](https://github.com/scalaz/scalaz-stream/blob/topic/0.8-redesign/implementation-notes.markdown#gadts)
120+
</small>
119121
---
120122

121123
# Sum Types and Product Types
122124

123-
Structurally:
125+
Speaking structurally:
124126

125127
```tut
126128
type Sum[A] = Lam[A] // Lift ∨ Tup ∨ Lambda ∨ App ∨ Fix
@@ -179,14 +181,42 @@
179181

180182
---
181183

184+
# Free Algebras
185+
186+
The group \\((Z,+)\\) of integers is free; we can take \\(S = {1}\\).
187+
188+
A monoid is free:
189+
190+
```tut:invisible
191+
trait Equal[F] { def equal(a: F, b: F): Boolean }
192+
```
193+
194+
```tut:silent
195+
trait Monoid[F] {
196+
def zero: F
197+
def append(a: F, b: F): F
198+
trait MonoidLaw {
199+
def associative(f1: F, f2: F, f3: F)(implicit F: Equal[F]) =
200+
F.equal(append(f1, append(f2, f3)), append(append(f1, f2), f3))
201+
def leftIdentity(a: F)(implicit F: Equal[F]) = F.equal(a, append(zero, a))
202+
def rightIdentity(a: F)(implicit F: Equal[F]) = F.equal(a, append(a, zero))
203+
}
204+
}
205+
```
206+
207+
`List[G]` is the canonical implementation of the Monoid Algebra.
208+
209+
`List[Set[G]]` is the canonical implementation of Classical Linear Logic (CLL).
210+
211+
---
212+
182213
# References
183214

184-
* [Algebraic Data Types](http://tpolecat.github.io/presentations/algebraic_types.html)
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)
188-
* [Sweeping crap APIs under the rug](http://tpolecat.github.io/presentations/lambdaconf14.html)
189-
by Rob Norris (@tpolecat)
215+
* [Algebraic Data Types](http://tpolecat.github.io/presentations/algebraic_types.html) by Rob Norris (@tpolecat)
216+
* [Encoding of GADTs in Scala](https://github.com/scalaz/scalaz-stream/blob/topic/0.8-redesign/implementation-notes.markdown#gadts) by Paul Chiusano (@pchiusano)
217+
* [Shapeless 2.1.0 Feature Overview](https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.1.0) by Miles Sabin (@milessabin)
218+
* [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) by Greg Meredith
219+
* [Sweeping crap APIs under the rug](http://tpolecat.github.io/presentations/lambdaconf14.html) by Rob Norris (@tpolecat)
190220

191221
</textarea>
192222
<script src="http://gnab.github.io/remark/downloads/remark-latest.min.js" type="text/javascript"></script>

0 commit comments

Comments
 (0)