Algebraic Data Type (ADT)
• Mathematics (algebra) just works in types
• Algebra = study of mathematical symbols and the rules
• e.g.
• Abstract Algebra = study of "algebraic structures"
• e.g. Magma, Semigroup, Monoid, Group, Ring, etc
• Data and rules inside the data set
• e.g. , ɹfor (Int, 0, )
(continued1)
1 The Algebra of Algebraic Data Types, Part 2 - Chris Taylor
Slide 31
Slide 31 text
Function as Exponential Object
• `A -> B` can be expressed as
• (Never -> A) Voidɹ㱻ɹ
• (A -> Never) Neverɹ㱻ɹ ɹ( )
• (Void -> A) Aɹ㱻ɹ
• (A -> Void) Voidɹ㱻ɹ
Slide 32
Slide 32 text
Exponent Laws
•
• (C -> B -> A) ((B, C) -> A)ɹ/* currying ! */
•
• (Either -> A) (B -> A, C -> A)
•
• (C -> (A, B)) (C -> A, C -> B)
Slide 33
Slide 33 text
Algebraic Data Type
=
and for types!
Slide 34
Slide 34 text
Appendix 1: Initial Algebra
ADT as fixed point of endofunctor (initial algebra):
e.g.
Slide 35
Slide 35 text
Appendix 2:
Derivative of ADT
...2 trees below the hole, and a list of
"above node value (A)", "left or right
side of the node subtree (Bool = 2)",
"node subtree (Tree)".
Slide 36
Slide 36 text
References
• The Algebra of Algebraic Data Types, Part 1 - Chris Taylor
• The algebra (and calculus!) of algebraic data types
• Understanding F-Algebras | Bartosz Milewski's
Programming Cafe
• ݍษڧձ ୈ7ճ @ ϫʔΫεΞϓϦέʔγϣϯζ
• Steve Awodey, Category Theory (2010)