Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/2DLgTqd.
Philip Wadler explains why category theory is of interest for developers and how categories model three basic data types: products (logical and), sums (logical or), and functions (logical implication). Filmed at qconsf.com.
Philip Wadler is Professor of Theoretical Computer Science at the University of Edinburgh and Senior Research Fellow at IOHK. He contributed to the designs of Haskell, Java, and XQuery, and is a co-author of Introduction to Functional Programming (Prentice Hall, 1988), XQuery from the Experts (Addison Wesley, 2004) and Generics and Collections in Java (O'Reilly, 2006).
2. InfoQ.com: News & Community Site
• Over 1,000,000 software developers, architects and CTOs read the site world-
wide every month
• 250,000 senior developers subscribe to our weekly newsletter
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• 2 dedicated podcast channels: The InfoQ Podcast, with a focus on
Architecture and The Engineering Culture Podcast, with a focus on building
• 96 deep dives on innovative topics packed as downloadable emags and
minibooks
• Over 40 new content items per week
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
category-theory-data-types
3. Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14. Products in Java
public class Product<A,B> {
private A fst;
private B snd;
public Product(A fst, B snd) {
this.fst = fst; this.snd = snd;
}
public A getFst() {
return this.fst;
}
public B getSnd() {
return this.snd;
}
}
15. Products in Java
public class Test {
public Product<Integer,String> pair =
new Product(1, “two”);
public Integer one = pair.getFst();
public String two = pair.getSnd();
}
17. Products in Haskell
pair :: Product Int String
pair = Pair 1 “two”
one :: Int
one = fst pair
two :: String
two = snd pair
18.
19.
20.
21.
22.
23.
24. Sums in Java
public interface Sum<A,B> {
public <C> C caseExpr(Function<A,C> f,
Function<B,C> g);
}
public class Left<A,B> implements Sum<A,B> {
private A x;
public Left(A x) { this.x = x; }
public <C> C caseExpr(Function<A,C> f,
Function<B,C> g) {
return f.apply(x);
}
}
public class Right<A,B> implements Sum<A,B> {
private B y;
public Right(B y) { this.y = y; }
public <C> C caseExpr(Function<A,C> f,
Function<B,C> g) {
return g.apply(y);
}
}
25. Sums in Java
public class ErrInt extends Sum<String,Integer> {
public ErrInt err = new Left(“error”);
public ErrInt one = new Right(1);
public ErrInt add(ErrInt that) {
return this.caseExpr(
e -> new Left(e),
m -> that.caseExpr(
e -> new Left(e),
n -> new Right(m+n)
)
);
public ErrInt test = one.add(err);
}
27. Sums in Haskell
type ErrInt = Sum String Int
err = Left “error”
one = Right 1
add :: ErrInt -> ErrInt -> ErrInt
add (Left e) that = Left e
add this (Left e) = Left e
add (Right m) (Right n) = Right (m+n)
test = add one err
28.
29.
30.
31.
32. Exponentials in Java
public class Test {
public Function<Integer,Integer>
add (Integer n) {
return x -> x + n;
}
public Function<Integer,Integer> incr =
add(1);
public Integer three = incr.apply(2);
}
33. Exponentials in Haskell
add :: Int -> (Int -> Int)
add n = x -> n + x
incr :: Int -> Int
incr = add 1
three :: Int
three = incr 2
34. Exponentials in Haskell
add :: Int -> Int -> Int
add n x = n + x
incr :: Int -> Int
incr = add 1
three :: Int
three = incr 2
35.
36.
37.
38. Further Reading
• Saunders MacLane, Categories for the Working
Mathematician
• Benjamin Pierce, Basic Category Theory for Computer
Scientists
• Bartosz Milewski, Programming Cafe (blog)
Bartosz Milewski's Programming Cafe
39. Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
category-theory-data-types