SlideShare une entreprise Scribd logo
1  sur  39
Categories for the
Working Hacker
Philip Wadler
University of Edinburgh
QCon SF, 15 Nov 2017
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
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
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;
}
}
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();
}
Products in Haskell
data Product a b =
Pair { fst :: a, snd :: b }
Products in Haskell
pair :: Product Int String
pair = Pair 1 “two”
one :: Int
one = fst pair
two :: String
two = snd pair
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);
}
}
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);
}
Sums in Haskell
data Sum a b = Left a | Right b
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
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);
}
Exponentials in Haskell
add :: Int -> (Int -> Int)
add n = x -> n + x
incr :: Int -> Int
incr = add 1
three :: Int
three = incr 2
Exponentials in Haskell
add :: Int -> Int -> Int
add n x = n + x
incr :: Int -> Int
incr = add 1
three :: Int
three = incr 2
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
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
category-theory-data-types

Contenu connexe

Similaire à Category Theory for the Working Hacker

Scientific Software: Sustainability, Skills & Sociology
Scientific Software: Sustainability, Skills & SociologyScientific Software: Sustainability, Skills & Sociology
Scientific Software: Sustainability, Skills & Sociology
Neil Chue Hong
 

Similaire à Category Theory for the Working Hacker (20)

Eco Expo: Website Globalization Case Study
Eco Expo: Website Globalization Case StudyEco Expo: Website Globalization Case Study
Eco Expo: Website Globalization Case Study
 
Life beyond Java 8
Life beyond Java 8Life beyond Java 8
Life beyond Java 8
 
Scientific Software: Sustainability, Skills & Sociology
Scientific Software: Sustainability, Skills & SociologyScientific Software: Sustainability, Skills & Sociology
Scientific Software: Sustainability, Skills & Sociology
 
Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive Programming
 
Scott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetupScott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetup
 
Vertx daitan
Vertx daitanVertx daitan
Vertx daitan
 
Vertx SouJava
Vertx SouJavaVertx SouJava
Vertx SouJava
 
Technical briefing on Software Release Planning
Technical briefing on Software Release PlanningTechnical briefing on Software Release Planning
Technical briefing on Software Release Planning
 
The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web Platform
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
 
A Practical Road to SaaS in Python
A Practical Road to SaaS in PythonA Practical Road to SaaS in Python
A Practical Road to SaaS in Python
 
F sharp - an overview
F sharp - an overviewF sharp - an overview
F sharp - an overview
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based Testing
 
OpenWhisk: Event-driven Design
OpenWhisk: Event-driven DesignOpenWhisk: Event-driven Design
OpenWhisk: Event-driven Design
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST Wars
 
Java beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application designJava beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application design
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingComputer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
 
Presentation on design pattern software project lll
 Presentation on design pattern  software project lll  Presentation on design pattern  software project lll
Presentation on design pattern software project lll
 
Measuring Technical Lag in Software Deployments (CHAOSScon 2020)
Measuring Technical Lag in Software Deployments (CHAOSScon 2020)Measuring Technical Lag in Software Deployments (CHAOSScon 2020)
Measuring Technical Lag in Software Deployments (CHAOSScon 2020)
 

Plus de C4Media

Plus de C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Category Theory for the Working Hacker

  • 1. Categories for the Working Hacker Philip Wadler University of Edinburgh QCon SF, 15 Nov 2017
  • 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(); }
  • 16. Products in Haskell data Product a b = Pair { fst :: a, snd :: b }
  • 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); }
  • 26. Sums in Haskell data Sum a b = Left a | Right b
  • 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