SlideShare ist ein Scribd-Unternehmen logo
1 von 68
Wearing the hair shirt A retrospective on Haskell Simon Peyton Jones Microsoft Research, Cambridge
Haskell is 15 years old (born FPCA 87)
Haskell is 15 years old  (born FPCA’87) Simon is 45 years old (born 18 Jan: POPL’58)
The primoridal soup ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Timeline Sept 87:  kick off Apr 90:  Haskell 1.0 May 92:  Haskell 1.2 (SIGPLAN Notices) (164pp) Aug 91:  Haskell 1.1 (153pp) May 96:  Haskell 1.3.  Monadic I/O, separate library report Apr 97:  Haskell 1.4 (213pp) Feb 99:  Haskell 98 (240pp) Dec 02:  Haskell 98 revised (260pp) The Book!
Haskell 98 Haskell development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reflections on the process ,[object Object],[object Object],[object Object],[object Object]
The price of usefulness ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reflections on process ,[object Object],[object Object],[object Object]
Syntax
Good ideas from other languages ,[object Object],head :: [a] -> a head (x:xs) = x head []  = error “head of nil” [(x,y) | x <- xs, y <- ys, x+y < 10] Separate type signatures DIY infix operators f `map` xs Optional layout let x = 3 y = 4 in x+y let { x = 3; y = 4} in x+y
Syntactic redundancy ,[object Object],[object Object],[object Object]
“ Declaration style”  ,[object Object],map f []  = [] map f (x:xs) = f x : map f xs sign x  | x>0  = 1 | x==0  = 0 | x<0  = -1
“ Expression style”  ,[object Object],map =  xs -> case xs of []  -> [] (x:xs) -> map f xs sign =  -> if x>0 then 1 else if x==0 then 0 else -1
Fat vs thin ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SLPJ’s conclusion syntactic redundancy is a big win Tony Hoare’s comment “I fear that Haskell is doomed to succeed”
Example (ICFP02 prog comp) sp_help item@(Item cur_loc cur_link _) wq vis | cur_length > limit   -- Beyond limit = sp wq vis | Just vis_link <- lookupVisited vis cur_loc =  -- Already visited; update the visited -- map if cur_link is better if cur_length >= linkLength vis_link then -- Current link is no better   sp wq vis else -- Current link is better   emit vis item ++ sp wq vis' | otherwise -- Not visited yet = emit vis item ++ sp wq' vis' where vis’ = ... wq  = ... Guard Pattern guard Pattern match Conditional Where clause
So much for syntax... What is important or interesting about Haskell?
What really matters? ,[object Object],[object Object],[object Object]
Laziness ,[object Object],[object Object],[object Object],[object Object]
But... ,[object Object],[object Object],[object Object],[object Object],So why wear the hair shirt of laziness?
Laziness ,[object Object],sp_help item@(Item cur_loc cur_link _) wq vis | cur_length > limit   -- Beyond limit = sp wq vis | Just vis_link <- lookupVisited vis cur_loc = if cur_length >= linkLength vis_link then   sp wq vis else   emit vis item ++ sp wq  vis' | otherwise = emit vis item ++ sp  wq'   vis' where vis’  = ... wq’   = ... Used in two cases Used in one case
Combinator libraries ,[object Object],type Parser a = String -> (a, String) exp :: Parser Expr exp = lit “let” <+> decls <+> lit “in” <+> exp ||| exp <+> aexp  ||| ...etc... This is illegal in ML, because of the value restriction Can only be made legal by eta expansion. But that breaks the Parser abstraction,  and is extremely gruesome: exp  x  =  ( lit “let” <+> decls <+> lit “in” <+> exp   ||| exp <+> aexp  ||| ...etc... ) x
The big one....
Laziness keeps you  honest ,[object Object],[object Object],[object Object],[object Object]
Monadic I/O ,[object Object],eg. getChar :: IO Char  putChar :: Char -> IO ()
Performing I/O ,[object Object],[object Object],[object Object],[object Object],main :: IO a
Connecting I/O operations (>>=)  :: IO a -> (a -> IO b) -> IO b return :: a -> IO a eg. getChar  >>=  (  -> getChar  >>=  (  -> putChar b >>=  ( ) -> return (a,b) )))
The do-notation ,[object Object],[object Object],[object Object],getChar  >>=  -> getChar  >>=  -> putchar b >>= )->  return (a,b) do   { a <- getChar; b <- getChar; putchar b; return (a,b) } ==
Control structures Values of type (IO t) are first class So we can define our own “control structures”   forever :: IO () -> IO () forever a = do { a; forever a } repeatN :: Int -> IO () -> IO () repeatN 0 a = return () repeatN n a = do { a; repeatN (n-1) a } e.g.  repeatN 10 (putChar ‘x’)
Monads generally ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Monads ,[object Object],[object Object],[object Object],Monad combinators (e.g. sequence, fold, etc), and do-notation, work over all monads
Example: a type checker tcExpr :: Expr -> Tc Type tcExpr (App fun arg) = do { fun_ty <- tcExpr fun ; arg_ty <- tcExpr arg ; res_ty <- newTyVar ; unify fun_ty (arg_ty --> res_ty) ; return res_ty } ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Robust to changes in plumbing
The IO monad ,[object Object],[object Object],[object Object]
What have we achieved? ,[object Object],Purely-functional core Imperative “skin”
What have we achieved? ,[object Object],[object Object],[object Object],[object Object],[object Object]
What we have not achieved ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Open challenge 1 Open problem: the IO monad has become Haskell’s sin-bin.  (Whenever we don’t understand something, we toss it in the IO monad.) Festering sore: unsafePerformIO :: IO a -> a Dangerous, indeed type-unsafe, but occasionally indispensable. Wanted: finer-grain effect partitioning e.g. IO {read x, write y} Int
Open challenge 2 Which would you prefer? do { a <- f x; b <- g y; h a b } h (f x) (g y) In a commutative monad, it does not matter whether we do  (f x)  first or  (g y) . Commutative   monads  are very common.  (Environment, unique supply, random number generation.)  For these, monads over-sequentialise. Wanted: theory and notation for some cool compromise.
Monad summary ,[object Object],[object Object],[object Object],[object Object]
Our biggest mistake ,[object Object],[object Object],[object Object]
What really matters? ,[object Object],[object Object],[object Object],[object Object]
SLPJ conclusions ,[object Object],[object Object],[object Object]
Type classes
Type classes ,[object Object],class Eq a where (==) :: a -> a -> Bool instance Eq Int where i1 == i2 = eqInt i1 i2 instance (Eq a) => Eq [a] where []  == []  = True (x:xs) == (y:ys) = (x == y) && (xs == ys) member :: Eq a => a -> [a] -> Bool member x []  = False member x (y:ys) | x==y  = True | otherwise = member x ys
Implementing type classes data Eq a = MkEq (a->a->Bool) eq (MkEq e) = e dEqInt :: Eq Int dEqInt = MkEq eqInt dEqList :: Eq a -> Eq [a] dEqList (MkEq e) = MkEq el where el []  []  = True   el (x:xs) (y:ys) = x `e` y && xs `el` ys member ::  Eq a  -> a -> [a] -> Bool member  d  x []  = False member  d  x (y:ys) |  eq d  x y  = True | otherwise = member  deq  x ys Class witnessed by a “dictionary” of methods Instance declarations create dictionaries Overloaded functions take extra dictionary parameter(s)
Type classes over time ,[object Object],Incomprehension Wild enthusiasm 1987 1989 1993 1997 Implementation begins Despair Hack, hack, hack  Hey, what’s the big deal?
Type classes are useful ,[object Object],[object Object],[object Object],class Monad m where return :: a -> m a (>>=)  :: m a -> (a -> m b) -> m b fail  :: String -> m a Note the higher-kinded type variable, m
Quickcheck ,[object Object],[object Object],[object Object],[object Object],[object Object],propRev :: [Int] -> Bool propRev xs = reverse (reverse xs) == xs propRevApp :: [Int] -> [Int] -> Bool propRevApp xs ys = reverse (xs++ys) ==   reverse ys ++ reverse xs
Quickcheck quickCheck :: Test a => a -> IO () class Test a where prop :: a -> Rand -> Bool class Arby a where arby :: Rand -> a  instance (Arby a, Test b) => Test (a->b) where prop f r = prop (f (arby r1)) r2   where (r1,r2) = split r instance Test Bool where prop b r = b
Extensiblity ,[object Object],[object Object]
Type-based dispatch ,[object Object],[object Object],class Num a where (+)  :: a -> a -> a negate  :: a -> a fromInteger :: Integer -> a ...
Type-based dispatch ,[object Object],[object Object],[object Object],[object Object],class Num a where (+)  :: a -> a -> a negate  :: a -> a fromInteger :: Integer -> a ...
Type-based dispatch ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Intensional polymorphism Haskell C.f. Crary et al   R (ICFP98), Baars et al (ICFP02)
Cool generalisations ,[object Object],[object Object],[object Object],[object Object],[object Object]
Qualified types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Type classes summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sexy types
Sexy types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Is sexy good?  Yes! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How sexy? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Destination =  F w <: ,[object Object],[object Object],C.f. Didier & Didier’s MLF work
Modules Power Difficulty Haskell 98 ML functors Haskell + sexy types
Modules Power Haskell 98 ML functors Haskell + sexy types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Modules ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Encapsulating it all runST :: (forall s. ST s a) -> a Stateful computation Pure result data ST s a -- Abstract newRef :: a -> ST s (STRef s a) read  :: STRef s a -> ST s a write  :: STRef s a -> a -> ST s () sort :: Ord a => [a] -> [a]  sort xs = runST (do { ..in-place sort.. })
Encapsulating it all runST :: (forall s. ST s a) -> a Higher rank type Monads Security of encapsulation depends on parametricity Parametricity depends on there being few polymorphic functions  (e.g.. f:: a->a means f is the identity function or bottom) And that depends on type classes to make non-parametric operations explicit  (e.g. f :: Ord a => a -> a) And it also depends on purity (no side effects)
Shirts off to Wadler ,[object Object],[object Object],[object Object]
The Haskell committee Arvind Lennart Augustsson Dave Barton Brian Boutel Warren Burton  Jon Fairbairn  Joseph Fasel  Andy Gordon  Maria Guzman Kevin Hammond  Ralf Hinze Paul Hudak [editor] John Hughes [editor] Thomas Johnsson Mark Jones Dick Kieburtz John Launchbury Erik Meijer  Rishiyur Nikhil John Peterson Simon Peyton Jones [editor] Mike Reeve Alastair Reid Colin Runciman Philip Wadler [editor] David Wise Jonathan Young

Weitere ähnliche Inhalte

Was ist angesagt?

Ceylon idioms by Gavin King
Ceylon idioms by Gavin KingCeylon idioms by Gavin King
Ceylon idioms by Gavin KingUnFroMage
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Piotr Paradziński
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog3Pillar Global
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless Jared Roesch
 
Scala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypeScala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypePhilip Schwarz
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does notSergey Bandysik
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java DevelopersMichael Galpin
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Philip Schwarz
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)Wim Vanderbauwhede
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Philip Schwarz
 
Introduction to join calculus
Introduction to join calculusIntroduction to join calculus
Introduction to join calculusSergei Winitzki
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Philip Schwarz
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...Philip Schwarz
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...Philip Schwarz
 

Was ist angesagt? (20)

Ceylon idioms by Gavin King
Ceylon idioms by Gavin KingCeylon idioms by Gavin King
Ceylon idioms by Gavin King
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Haskell
HaskellHaskell
Haskell
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
Scala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypeScala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data Type
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
2 kotlin vs. java: what java has that kotlin does not
2  kotlin vs. java: what java has that kotlin does not2  kotlin vs. java: what java has that kotlin does not
2 kotlin vs. java: what java has that kotlin does not
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 
Introduction to join calculus
Introduction to join calculusIntroduction to join calculus
Introduction to join calculus
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
 

Andere mochten auch

Haskellテストスライド
HaskellテストスライドHaskellテストスライド
HaskellテストスライドShoko Sasaki
 
Puerto Colombia en fotos.
Puerto Colombia en fotos.Puerto Colombia en fotos.
Puerto Colombia en fotos.nayibe1
 
颐信科技有限公司
颐信科技有限公司颐信科技有限公司
颐信科技有限公司ecguard
 
Programmazione funzionale: un primo approccio attraverso F#
Programmazione funzionale: un primo approccio attraverso F#Programmazione funzionale: un primo approccio attraverso F#
Programmazione funzionale: un primo approccio attraverso F#Commit University
 
QuickCheck - Software Testing
QuickCheck - Software TestingQuickCheck - Software Testing
QuickCheck - Software TestingJavran
 

Andere mochten auch (7)

Haskellテストスライド
HaskellテストスライドHaskellテストスライド
Haskellテストスライド
 
Puerto Colombia en fotos.
Puerto Colombia en fotos.Puerto Colombia en fotos.
Puerto Colombia en fotos.
 
Tbja flyer
Tbja flyerTbja flyer
Tbja flyer
 
颐信科技有限公司
颐信科技有限公司颐信科技有限公司
颐信科技有限公司
 
Programmazione funzionale: un primo approccio attraverso F#
Programmazione funzionale: un primo approccio attraverso F#Programmazione funzionale: un primo approccio attraverso F#
Programmazione funzionale: un primo approccio attraverso F#
 
QuickCheck - Software Testing
QuickCheck - Software TestingQuickCheck - Software Testing
QuickCheck - Software Testing
 
Symfony and eZ Publish
Symfony and eZ PublishSymfony and eZ Publish
Symfony and eZ Publish
 

Ähnlich wie Haskell retrospective

Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with classTiago Babo
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanJimin Hsieh
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingGo Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingLex Sheehan
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 

Ähnlich wie Haskell retrospective (20)

Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with class
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingGo Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional Programming
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 

Kürzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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...Martijn de Jong
 
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.pptxEarley Information Science
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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.pptxMalak Abu Hammad
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 slidevu2urc
 
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 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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 DevelopmentsTrustArc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Haskell retrospective

  • 1. Wearing the hair shirt A retrospective on Haskell Simon Peyton Jones Microsoft Research, Cambridge
  • 2. Haskell is 15 years old (born FPCA 87)
  • 3. Haskell is 15 years old (born FPCA’87) Simon is 45 years old (born 18 Jan: POPL’58)
  • 4.
  • 5. Timeline Sept 87: kick off Apr 90: Haskell 1.0 May 92: Haskell 1.2 (SIGPLAN Notices) (164pp) Aug 91: Haskell 1.1 (153pp) May 96: Haskell 1.3. Monadic I/O, separate library report Apr 97: Haskell 1.4 (213pp) Feb 99: Haskell 98 (240pp) Dec 02: Haskell 98 revised (260pp) The Book!
  • 6.
  • 7.
  • 8.
  • 9.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Example (ICFP02 prog comp) sp_help item@(Item cur_loc cur_link _) wq vis | cur_length > limit -- Beyond limit = sp wq vis | Just vis_link <- lookupVisited vis cur_loc = -- Already visited; update the visited -- map if cur_link is better if cur_length >= linkLength vis_link then -- Current link is no better sp wq vis else -- Current link is better emit vis item ++ sp wq vis' | otherwise -- Not visited yet = emit vis item ++ sp wq' vis' where vis’ = ... wq = ... Guard Pattern guard Pattern match Conditional Where clause
  • 17. So much for syntax... What is important or interesting about Haskell?
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 24.
  • 25.
  • 26.
  • 27. Connecting I/O operations (>>=) :: IO a -> (a -> IO b) -> IO b return :: a -> IO a eg. getChar >>= ( -> getChar >>= ( -> putChar b >>= ( ) -> return (a,b) )))
  • 28.
  • 29. Control structures Values of type (IO t) are first class So we can define our own “control structures” forever :: IO () -> IO () forever a = do { a; forever a } repeatN :: Int -> IO () -> IO () repeatN 0 a = return () repeatN n a = do { a; repeatN (n-1) a } e.g. repeatN 10 (putChar ‘x’)
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Open challenge 1 Open problem: the IO monad has become Haskell’s sin-bin. (Whenever we don’t understand something, we toss it in the IO monad.) Festering sore: unsafePerformIO :: IO a -> a Dangerous, indeed type-unsafe, but occasionally indispensable. Wanted: finer-grain effect partitioning e.g. IO {read x, write y} Int
  • 38. Open challenge 2 Which would you prefer? do { a <- f x; b <- g y; h a b } h (f x) (g y) In a commutative monad, it does not matter whether we do (f x) first or (g y) . Commutative monads are very common. (Environment, unique supply, random number generation.) For these, monads over-sequentialise. Wanted: theory and notation for some cool compromise.
  • 39.
  • 40.
  • 41.
  • 42.
  • 44.
  • 45. Implementing type classes data Eq a = MkEq (a->a->Bool) eq (MkEq e) = e dEqInt :: Eq Int dEqInt = MkEq eqInt dEqList :: Eq a -> Eq [a] dEqList (MkEq e) = MkEq el where el [] [] = True el (x:xs) (y:ys) = x `e` y && xs `el` ys member :: Eq a -> a -> [a] -> Bool member d x [] = False member d x (y:ys) | eq d x y = True | otherwise = member deq x ys Class witnessed by a “dictionary” of methods Instance declarations create dictionaries Overloaded functions take extra dictionary parameter(s)
  • 46.
  • 47.
  • 48.
  • 49. Quickcheck quickCheck :: Test a => a -> IO () class Test a where prop :: a -> Rand -> Bool class Arby a where arby :: Rand -> a instance (Arby a, Test b) => Test (a->b) where prop f r = prop (f (arby r1)) r2 where (r1,r2) = split r instance Test Bool where prop b r = b
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62. Modules Power Difficulty Haskell 98 ML functors Haskell + sexy types
  • 63.
  • 64.
  • 65. Encapsulating it all runST :: (forall s. ST s a) -> a Stateful computation Pure result data ST s a -- Abstract newRef :: a -> ST s (STRef s a) read :: STRef s a -> ST s a write :: STRef s a -> a -> ST s () sort :: Ord a => [a] -> [a] sort xs = runST (do { ..in-place sort.. })
  • 66. Encapsulating it all runST :: (forall s. ST s a) -> a Higher rank type Monads Security of encapsulation depends on parametricity Parametricity depends on there being few polymorphic functions (e.g.. f:: a->a means f is the identity function or bottom) And that depends on type classes to make non-parametric operations explicit (e.g. f :: Ord a => a -> a) And it also depends on purity (no side effects)
  • 67.
  • 68. The Haskell committee Arvind Lennart Augustsson Dave Barton Brian Boutel Warren Burton Jon Fairbairn Joseph Fasel Andy Gordon Maria Guzman Kevin Hammond Ralf Hinze Paul Hudak [editor] John Hughes [editor] Thomas Johnsson Mark Jones Dick Kieburtz John Launchbury Erik Meijer Rishiyur Nikhil John Peterson Simon Peyton Jones [editor] Mike Reeve Alastair Reid Colin Runciman Philip Wadler [editor] David Wise Jonathan Young