SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Pure Laziness
An Exploration of Haskell
Mitchell Vitez
Purely functional
No hidden state, no side effects
Non-strict
Lazy
Referentially transparent
Can replace expressions with their values
Pattern Matching
Little did I know then
Currying
Partial function application
Statically typed
Type inference
Strongly typed
Type variables
Typeclasses
Interpreted or compiled
Words words words
Haskell Curry
f a b = a + b
f 1 2 == 3
f :: Int -> Int -> Int
f a b = a + b
A f a b ulous example
1 : 2 : 3 : []
[1, 2, 3]
head [1, 2, 3] == 1
head :: [a] -> a
head [] = error "empty"
head (x:xs) = x
Ahead of the game
zip [1,2,3] [4,5,6]
[(1,4), (2,5), (3,6)]
zip :: [a] -> [b] -> [(a,b)]
zip (x:xs) (y:ys) =
(x, y) : zip xs ys
zip _ _ = []
zip-a-Dee-Doo-Dah
First-class functions
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith f (x:xs) (y:xs) =
f x y : zipWith f xs ys
zipWith _ _ _ = []
zip = zipWith (,)
I Like Ike
Generalizing How We're Using Zip
addOne = (1 +)
addOne 5 == 6
zip = zipWith (,)
(+) :: Num a => a -> a -> a
addOne :: Num a => a -> a
Curry on my wayward sum
Moses Schönfinkel
Parametric polymorphism
(+) :: Num a => a -> a -> a
f :: a -> a -> Bool
g :: Eq a => a -> a -> Bool
Theorems for free
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
x /= y = not (x == y)
instance Eq MyType where
x == y = checkXYequality
Do it with Typeclass
f x y = x
f 1 undefined
Add indices to a list
zip xs [0..]
Laziness to infinity
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
fib n = fibs !! n
A nod to the canon
Learn You a Haskell
Real World Haskell
haskellbook.com
CIS 194
Monad Challenges
A History of Haskell: Being Lazy With
Class
Resources

Weitere ähnliche Inhalte

Was ist angesagt?

NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
Atsuo Ishimoto
 
Bloom filter
Bloom filterBloom filter
Bloom filter
feng lee
 

Was ist angesagt? (20)

Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Chapter7
Chapter7Chapter7
Chapter7
 
NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
NumPyの歴史とPythonの並行処理【PyData.tokyo One-day Conference 2018】
 
Bloom filter
Bloom filterBloom filter
Bloom filter
 
行列演算とPythonの言語デザイン
行列演算とPythonの言語デザイン行列演算とPythonの言語デザイン
行列演算とPythonの言語デザイン
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
 
Otter 2017-12-18-01-ss
Otter 2017-12-18-01-ssOtter 2017-12-18-01-ss
Otter 2017-12-18-01-ss
 
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle TreesModern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
 
Arrays
ArraysArrays
Arrays
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
 
First class patterns for object matching
First class patterns for object matchingFirst class patterns for object matching
First class patterns for object matching
 
Phorms: Pattern Matching Library for Pharo
Phorms: Pattern Matching Library for PharoPhorms: Pattern Matching Library for Pharo
Phorms: Pattern Matching Library for Pharo
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel Summit
 
PROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In PrologPROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In Prolog
 
関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡
 
Haskell
HaskellHaskell
Haskell
 
van Emde Boas trees
van Emde Boas treesvan Emde Boas trees
van Emde Boas trees
 
Sets
SetsSets
Sets
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 
Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)
 

Andere mochten auch

State of the Student Association Report 2013
State of the Student Association Report 2013State of the Student Association Report 2013
State of the Student Association Report 2013
Grace S. Park
 

Andere mochten auch (7)

State of the Student Association Report 2013
State of the Student Association Report 2013State of the Student Association Report 2013
State of the Student Association Report 2013
 
Polymyositis
PolymyositisPolymyositis
Polymyositis
 
32 ch lesson 24 laziness by Hallerin Hilton Hill
32 ch lesson 24   laziness by Hallerin Hilton Hill32 ch lesson 24   laziness by Hallerin Hilton Hill
32 ch lesson 24 laziness by Hallerin Hilton Hill
 
How to overcome laziness
How to overcome lazinessHow to overcome laziness
How to overcome laziness
 
a case presentation of polymyositis
a case presentation of polymyositisa case presentation of polymyositis
a case presentation of polymyositis
 
What Causes Laziness? - By Simeon Adedokun
What Causes Laziness? - By Simeon AdedokunWhat Causes Laziness? - By Simeon Adedokun
What Causes Laziness? - By Simeon Adedokun
 
Polymyositis Dermatomyositis
Polymyositis DermatomyositisPolymyositis Dermatomyositis
Polymyositis Dermatomyositis
 

Ähnlich wie Pure Laziness: An Exploration of Haskell

Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
Bryan O'Sullivan
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
Bryan O'Sullivan
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
djspiewak
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
Bryan O'Sullivan
 

Ähnlich wie Pure Laziness: An Exploration of Haskell (20)

Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with class
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Haskell
HaskellHaskell
Haskell
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Numerical analysisgroup19
Numerical analysisgroup19Numerical analysisgroup19
Numerical analysisgroup19
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
An Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using HaskellAn Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using Haskell
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 

Kürzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Pure Laziness: An Exploration of Haskell

  • 1. Pure Laziness An Exploration of Haskell Mitchell Vitez
  • 2. Purely functional No hidden state, no side effects Non-strict Lazy Referentially transparent Can replace expressions with their values Pattern Matching Little did I know then
  • 3. Currying Partial function application Statically typed Type inference Strongly typed Type variables Typeclasses Interpreted or compiled Words words words Haskell Curry
  • 4. f a b = a + b f 1 2 == 3 f :: Int -> Int -> Int f a b = a + b A f a b ulous example
  • 5. 1 : 2 : 3 : [] [1, 2, 3] head [1, 2, 3] == 1 head :: [a] -> a head [] = error "empty" head (x:xs) = x Ahead of the game
  • 6. zip [1,2,3] [4,5,6] [(1,4), (2,5), (3,6)] zip :: [a] -> [b] -> [(a,b)] zip (x:xs) (y:ys) = (x, y) : zip xs ys zip _ _ = [] zip-a-Dee-Doo-Dah
  • 7. First-class functions zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] zipWith f (x:xs) (y:xs) = f x y : zipWith f xs ys zipWith _ _ _ = [] zip = zipWith (,) I Like Ike Generalizing How We're Using Zip
  • 8. addOne = (1 +) addOne 5 == 6 zip = zipWith (,) (+) :: Num a => a -> a -> a addOne :: Num a => a -> a Curry on my wayward sum Moses Schönfinkel
  • 9. Parametric polymorphism (+) :: Num a => a -> a -> a f :: a -> a -> Bool g :: Eq a => a -> a -> Bool Theorems for free
  • 10. class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool x /= y = not (x == y) instance Eq MyType where x == y = checkXYequality Do it with Typeclass
  • 11. f x y = x f 1 undefined Add indices to a list zip xs [0..] Laziness to infinity
  • 12. fibs = 0 : 1 : zipWith (+) fibs (tail fibs) fib n = fibs !! n A nod to the canon
  • 13. Learn You a Haskell Real World Haskell haskellbook.com CIS 194 Monad Challenges A History of Haskell: Being Lazy With Class Resources