

The Algebra of Data and the Calculus of Mutation - thekguy
http://blog.lab49.com/archives/3011

======
scott_s
I didn't get the + operation on types until he compared it to C's union. I
don't know why he didn't appeal to the logical operations "and" and "or" for *
and +, because that's what finally made them click and be consistent for me.
For example, you can read int * int as "A type with an int _and_ an int," and
you can read int + int as "A type with an int on the left _or_ an int on the
right."

The links to the papers by Conor McBride are broken, but you can find them
here: <http://strictlypositive.org/publications.html>

~~~
joeyespo
Yeah it's definitely helpful to think of it that way.

I usually relate it to sets. Types are sets of possible objects, "+" indicates
set-based union, and "*" is just the Cartesian product of the types.

~~~
munificent
"+" isn't set union. If it was, int+int would just be int. The extra tag
distinguishes it. Raw unions in C _are_ like set union though.

~~~
joeyespo
Right, it's a tagged union. I mean conceptually. You still end up with the
same domain of objects as a union. The tag just tells you which domain you're
object is in. (Or which side rather, since the domains can intersect.)

------
swift
This is a great explanation of algebraic datatypes!

The notion of one-hole context, its connection to differentiation, and its
application to zippers is really interesting stuff. Another (much more
detailed) discussion of it can be found here:
<http://en.wikibooks.org/wiki/Haskell/Zippers>

~~~
calebmpeterson
Agreed, the "if this looks like a derivative it's because it is" punchline
made my jaw drop. I <i>never</i> expected to see calculus show up when
discussing ADT's and mutation.

The notion is so contrary to the way I'm used to thinking about programming
and yet so appropriate given that mutation is change and a derivative
describes the rate of change.

I want some more!

------
gmartres
Further explanations on the "Mu" thing and its relation with catamorphism[0](a
fold[1] that works on every datatype):
[http://stackoverflow.com/questions/4434292/catamorphism-
and-...](http://stackoverflow.com/questions/4434292/catamorphism-and-tree-
traversing-in-haskell/4435137#4435137) and
[http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/acmmp...](http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/acmmpc-
calcfp.pdf)

[0]: <https://secure.wikimedia.org/wikipedia/en/wiki/Catamorphism>

[1]:
[https://secure.wikimedia.org/wikipedia/en/wiki/Fold_%28highe...](https://secure.wikimedia.org/wikipedia/en/wiki/Fold_%28higher-
order_function%29)

