Why Haskell?   Susan Potter   March 2012
What is Haskell?    Figure:   "pure functional, lazy, polymorphic, statically and strongly typed with type inference . . . "
How can I drive this thing? Figure: Photo from "If programming languages were cars" blog post           http://machinegest...
Can I drive Haskell without all this? Figure: No need to know Category Theory proofs, just some intuitions!
# finger $(whoami)Login: susan               Name: Susan PotterDirectory: /home/susan     Shell: /bin/zshPracticing since ...
Are we "doing it wrong"?         Figure: Maybe! ;)          http://absolutelymadness.tumblr.com/post/17567574522
Overview: Choosing a language    Many considerations    political, human, technical    Runtime    performance, reliability...
Overview: Choosing a language    Many considerations    political, human, technical    Runtime    performance, reliability...
Overview: Choosing a language    Many considerations    political, human, technical    Runtime    performance, reliability...
Overview: Choosing a language    Many considerations    political, human, technical    Runtime    performance, reliability...
Overview: Agenda    My Claims / Hypotheses    Laziness, Functional, Type System    Toolkit & Runtime    Library Ecosystem ...
My Claims    Performance is reasonable    on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt ben...
My Claims    Performance is reasonable    on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt ben...
My Claims    Performance is reasonable    on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt ben...
My Claims    Performance is reasonable    on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt ben...
Haskell "lazy" by default       Figure: Photo by Mark Fischer            http://www.flickr.com/photos/tom_ruaat/4431626234/
Haskell "lazy" by default       Figure: Photo by Mark Fischer            http://www.flickr.com/photos/tom_ruaat/4431626234...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value    doubleSum 3 (2 + 3)     → doubleSum 3 5     → 2 * (3 + 5)     → 2 * 8 ...
Example: doubleSum 3 (2 + 3)       Call by value       (evaluates inner-most expressions first)    doubleSum 3 (2 + 3)     ...
Example: doubleSum 3 (2 + 3)       Call by value       (evaluates inner-most expressions first)    doubleSum 3 (2 + 3)     ...
Example: doubleSum 3 (2 + 3)       Call by value       (evaluates inner-most expressions first)    doubleSum 3 (2 + 3)     ...
Example: doubleSum 3 (2 + 3)       Call by value       (evaluates inner-most expressions first)    doubleSum 3 (2 + 3)     ...
Example: doubleSum 3 (2 + 3)       Call by value       (evaluates inner-most expressions first)    doubleSum 3 (2 + 3)     ...
Laziness in Haskell is . . . CallByName + SharingOptimization + PossibleMinorOverhead
Laziness: Buyer Beware    filter (λ x → x < 6) [1..]    (never terminates)    takeWhile (λ x → x < 6) [1..]    (does termi...
Laziness: Buyer Beware    filter (λ x → x < 6) [1..]    (never terminates)    takeWhile (λ x → x < 6) [1..]    (does termi...
Laziness: Buyer Beware    filter (λ x → x < 6) [1..]    (never terminates)    takeWhile (λ x → x < 6) [1..]    (does termi...
Laziness: Buyer Beware    filter (λ x → x < 6) [1..]    (never terminates)    takeWhile (λ x → x < 6) [1..]    (does termi...
Laziness: Buyer Beware    filter (λ x → x < 6) [1..]    (never terminates)    takeWhile (λ x → x < 6) [1..]    (does termi...
Laziness: Also Pretty Suuweeeet!     Infinite sequences/lists     made possible     Recursive functions     become practica...
Laziness: Also Pretty Suuweeeet!     Infinite sequences/lists     made possible     Recursive functions     become practica...
Laziness: Also Pretty Suuweeeet!     Infinite sequences/lists     made possible     Recursive functions     become practica...
Laziness: Also Pretty Suuweeeet!     Infinite sequences/lists     made possible     Recursive functions     become practica...
Purity + Laziness=> Reasoning     Equality (referential transparency)     Can replace occurrences of LHS with RHS     High...
Purity + Laziness=> Reasoning     Equality (referential transparency)     Can replace occurrences of LHS with RHS     High...
Purity + Laziness=> Reasoning     Equality (referential transparency)     Can replace occurrences of LHS with RHS     High...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a ...
class Monoid m where  mappend :: m -> m -> m  mempty :: minstance Num a => Monoid a where  mappend :: m -> m -> m  mappend...
class Monoid m where  mappend :: m -> m -> m  mempty :: minstance Num a => Monoid a where  mappend :: m -> m -> m  mappend...
class Monoid m where  mappend :: m -> m -> m  mempty :: minstance Num a => Monoid a where  mappend :: m -> m -> m  mappend...
Haskell type signatures can . . .     express side effects     e.g. String -> IO Int     declare computational strategies ...
Haskell type signatures can . . .     express side effects     e.g. String -> IO Int     declare computational strategies ...
Haskell type signatures can . . .     express side effects     e.g. String -> IO Int     declare computational strategies ...
Haskell type signatures can . . .     express side effects     e.g. String -> IO Int     declare computational strategies ...
Haskell type signatures can . . .     express side effects     e.g. String -> IO Int     declare computational strategies ...
Interfaces in OO . . .  Figure: Class definitions are married to the interfaces they implement.
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
Interfaces in Haskell: Typeclasses. . .     Decouple type definition from interface     Allow upstream implementations     ...
class (Eq a) => Ord a where  compare                 :: a -> a -> Ordering  compare x y | x == y    = EQ              | x ...
Typically this just works . . .   data SimpleShape = Square { size :: Double }                    | Circle { radius :: Dou...
Are you awake? Figure: http://absolutelymadness.tumblr.com/post/18126913457
Haskell Tooling: Libraries         Quite a few         Practical libraries         Often freely available         Permissi...
Haskell Tooling: Libraries         Quite a few         Practical libraries         Often freely available         Permissi...
Haskell Tooling: Libraries         Quite a few         Practical libraries         Often freely available         Permissi...
Haskell Tooling: Libraries         Quite a few         Practical libraries         Often freely available         Permissi...
Haskell Tooling: Runtime         Reasonably performant         between JVM 7 and C# Mono performance         GC settings e...
Haskell Tooling: Runtime         Reasonably performant         between JVM 7 and C# Mono performance         GC settings e...
Haskell Tooling: Runtime         Reasonably performant         between JVM 7 and C# Mono performance         GC settings e...
Haskell Tooling: Tools         Testing tools         QuickCheck, HUnit         Documentation tools         Haddock, Hoogle...
Haskell Tooling: Tools         Testing tools         QuickCheck, HUnit         Documentation tools         Haddock, Hoogle...
Haskell Tooling: Tools         Testing tools         QuickCheck, HUnit         Documentation tools         Haddock, Hoogle...
Haskell Tooling: DependencyManagement        Hackage        database of freely available Haskell libraries        Cabal   ...
Haskell Tooling: DependencyManagement        Hackage        database of freely available Haskell libraries        Cabal   ...
Haskell Tooling: DependencyManagement        Hackage        database of freely available Haskell libraries        Cabal   ...
Haskell Tooling: DependencyManagement        Hackage        database of freely available Haskell libraries        Cabal   ...
Haskell Tooling: Don’ts for Newbies     Use GHC (not HUGS)     Hugs written for educational purposes not industrial usage ...
Haskell Tooling: Don’ts for Newbies     Use GHC (not HUGS)     Hugs written for educational purposes not industrial usage ...
Haskell Tooling: Don’ts for Newbies     Use GHC (not HUGS)     Hugs written for educational purposes not industrial usage ...
Haskell Tooling: Don’ts for Newbies     Use GHC (not HUGS)     Hugs written for educational purposes not industrial usage ...
Haskell Tooling: Suggestions         Explicit language extensions         Intentionally and explicitly enable per module  ...
Haskell Tooling: Suggestions         Explicit language extensions         Intentionally and explicitly enable per module  ...
Haskell Tooling: Suggestions         Explicit language extensions         Intentionally and explicitly enable per module  ...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Oh, the possibilities!     Parallel / Concurrency Options     threads, dataflow, par, seq     "Cloud" Haskell     A kind of...
Questions?        Figure:   http://www.flickr.com/photos/42682395@N04/         @SusanPotter
Questions?        Figure:   http://www.flickr.com/photos/42682395@N04/         @SusanPotter
Bonus: References / Resources    Channel 9 Lectures (Erik Meijer)    http://channel9.msdn.com/Shows/Going+Deep/    Lecture...
Bonus: References / Resources    Channel 9 Lectures (Erik Meijer)    http://channel9.msdn.com/Shows/Going+Deep/    Lecture...
Bonus: References / Resources    Channel 9 Lectures (Erik Meijer)    http://channel9.msdn.com/Shows/Going+Deep/    Lecture...
Bonus: References / Resources    Channel 9 Lectures (Erik Meijer)    http://channel9.msdn.com/Shows/Going+Deep/    Lecture...
Bonus: References / Resources    Channel 9 Lectures (Erik Meijer)    http://channel9.msdn.com/Shows/Going+Deep/    Lecture...
Bonus: Brief QuickCheck Examplemodule Tests whereimport Test.QuickCheck (quickCheck)propReverseReverse :: [Char] -> Boolpr...
Upcoming SlideShare
Loading in...5
×

Why Haskell

7,042

Published on

Monads, also known as Kleisli triples in Category Theory, are an (endo-)functor together with two natural transformations, which are surprisingly useful in pure languages like Haskell, but this talk will NOT reference monads. Ever. (Well, at least not in this talk.)

Instead what I intend to impress upon an audience of newcomers to Haskell is the wide array of freely available libraries most of which are liberally licensed open source software, intuitive package management, practical build tools, reasonable documentation (when you know how to read it and where to find it), interactive shell (or REPL), mature compiler, stable runtime, testing tools that will blow your mind away, and a small but collaborative and knowledgeable community of developers. Oh, and some special features of Haskell - the language - too!

Published in: Technology, Education
1 Comment
23 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,042
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
140
Comments
1
Likes
23
Embeds 0
No embeds

No notes for slide

Why Haskell

  1. 1. Why Haskell? Susan Potter March 2012
  2. 2. What is Haskell? Figure: "pure functional, lazy, polymorphic, statically and strongly typed with type inference . . . "
  3. 3. How can I drive this thing? Figure: Photo from "If programming languages were cars" blog post http://machinegestalt.posterous.com/if-programming-languages-were-cars
  4. 4. Can I drive Haskell without all this? Figure: No need to know Category Theory proofs, just some intuitions!
  5. 5. # finger $(whoami)Login: susan Name: Susan PotterDirectory: /home/susan Shell: /bin/zshPracticing since 1997-09-29 21:18 (GMT) on tty1 from :0Too much unread mail on me@susanpotter.netNow working at Desk.com! Looking for smart developers!;)Plan: github: mbbx6spp twitter: @SusanPotter
  6. 6. Are we "doing it wrong"? Figure: Maybe! ;) http://absolutelymadness.tumblr.com/post/17567574522
  7. 7. Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, configurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, configuration, deployment
  8. 8. Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, configurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, configuration, deployment
  9. 9. Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, configurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, configuration, deployment
  10. 10. Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, configurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, configuration, deployment
  11. 11. Overview: Agenda My Claims / Hypotheses Laziness, Functional, Type System Toolkit & Runtime Library Ecosystem Pitfalls & Hurdles
  12. 12. My Claims Performance is reasonable on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt benchmarks http://shootout.alioth.debian.org/u64q/haskell.php Productivity with long-term benefits after initial steep learning curve Haskell types offer stronger verifiability strong and meaningful checks applied Pure functional code is easier to test probably not controversial
  13. 13. My Claims Performance is reasonable on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt benchmarks http://shootout.alioth.debian.org/u64q/haskell.php Productivity with long-term benefits after initial steep learning curve Haskell types offer stronger verifiability strong and meaningful checks applied Pure functional code is easier to test probably not controversial
  14. 14. My Claims Performance is reasonable on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt benchmarks http://shootout.alioth.debian.org/u64q/haskell.php Productivity with long-term benefits after initial steep learning curve Haskell types offer stronger verifiability strong and meaningful checks applied Pure functional code is easier to test probably not controversial
  15. 15. My Claims Performance is reasonable on par with Java and C# Mono; 2-3x CPU times of C (approx); BUT always doubt benchmarks http://shootout.alioth.debian.org/u64q/haskell.php Productivity with long-term benefits after initial steep learning curve Haskell types offer stronger verifiability strong and meaningful checks applied Pure functional code is easier to test probably not controversial
  16. 16. Haskell "lazy" by default Figure: Photo by Mark Fischer http://www.flickr.com/photos/tom_ruaat/4431626234/
  17. 17. Haskell "lazy" by default Figure: Photo by Mark Fischer http://www.flickr.com/photos/tom_ruaat/4431626234/ (jarring for mainstream programmers)
  18. 18. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  19. 19. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  20. 20. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  21. 21. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  22. 22. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  23. 23. Example: doubleSum 3 (2 + 3) Call by value doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  24. 24. Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions first) doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  25. 25. Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions first) doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  26. 26. Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions first) doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  27. 27. Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions first) doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  28. 28. Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions first) doubleSum 3 (2 + 3) → doubleSum 3 5 → 2 * (3 + 5) → 2 * 8 → 16 Call by name (evaluates outer-most expressions first) doubleSum 3 (2 + 3) → (λ x -> 2 * (3 + x)) (2 + 3)
  29. 29. Laziness in Haskell is . . . CallByName + SharingOptimization + PossibleMinorOverhead
  30. 30. Laziness: Buyer Beware filter (λ x → x < 6) [1..] (never terminates) takeWhile (λ x → x < 6) [1..] (does terminate) dropWhile (λ x → x >= 6) [1..] (does not terminate) Need to understand implications of laziness on functions Laziness with I/O implications lazy I/O with handles is problematic, but iteratee idiom solves most of these. There are a number of libraries available to help with this: enumerator, pipes, . . .
  31. 31. Laziness: Buyer Beware filter (λ x → x < 6) [1..] (never terminates) takeWhile (λ x → x < 6) [1..] (does terminate) dropWhile (λ x → x >= 6) [1..] (does not terminate) Need to understand implications of laziness on functions Laziness with I/O implications lazy I/O with handles is problematic, but iteratee idiom solves most of these. There are a number of libraries available to help with this: enumerator, pipes, . . .
  32. 32. Laziness: Buyer Beware filter (λ x → x < 6) [1..] (never terminates) takeWhile (λ x → x < 6) [1..] (does terminate) dropWhile (λ x → x >= 6) [1..] (does not terminate) Need to understand implications of laziness on functions Laziness with I/O implications lazy I/O with handles is problematic, but iteratee idiom solves most of these. There are a number of libraries available to help with this: enumerator, pipes, . . .
  33. 33. Laziness: Buyer Beware filter (λ x → x < 6) [1..] (never terminates) takeWhile (λ x → x < 6) [1..] (does terminate) dropWhile (λ x → x >= 6) [1..] (does not terminate) Need to understand implications of laziness on functions Laziness with I/O implications lazy I/O with handles is problematic, but iteratee idiom solves most of these. There are a number of libraries available to help with this: enumerator, pipes, . . .
  34. 34. Laziness: Buyer Beware filter (λ x → x < 6) [1..] (never terminates) takeWhile (λ x → x < 6) [1..] (does terminate) dropWhile (λ x → x >= 6) [1..] (does not terminate) Need to understand implications of laziness on functions Laziness with I/O implications lazy I/O with handles is problematic, but iteratee idiom solves most of these. There are a number of libraries available to help with this: enumerator, pipes, . . .
  35. 35. Laziness: Also Pretty Suuweeeet! Infinite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ...
  36. 36. Laziness: Also Pretty Suuweeeet! Infinite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ...
  37. 37. Laziness: Also Pretty Suuweeeet! Infinite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ...
  38. 38. Laziness: Also Pretty Suuweeeet! Infinite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ...
  39. 39. Purity + Laziness=> Reasoning Equality (referential transparency) Can replace occurrences of LHS with RHS Higher Order Functions encourage exploitation of higher-level patterns Function Composition leads to greater reuse
  40. 40. Purity + Laziness=> Reasoning Equality (referential transparency) Can replace occurrences of LHS with RHS Higher Order Functions encourage exploitation of higher-level patterns Function Composition leads to greater reuse
  41. 41. Purity + Laziness=> Reasoning Equality (referential transparency) Can replace occurrences of LHS with RHS Higher Order Functions encourage exploitation of higher-level patterns Function Composition leads to greater reuse
  42. 42. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  43. 43. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  44. 44. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  45. 45. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  46. 46. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  47. 47. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  48. 48. mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xsmyproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xsmyany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr ( x b -> b || pred x) False xsmyall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr ( x b -> b && pred x) True xs
  49. 49. class Monoid m where mappend :: m -> m -> m mempty :: minstance Num a => Monoid a where mappend :: m -> m -> m mappend x y = (+) x y mempty :: m mempty = 0instance Monoid Bool where mappend :: m -> m -> m mappend True _ = True mappend _ True = True mappend _ _ = False mempty :: m
  50. 50. class Monoid m where mappend :: m -> m -> m mempty :: minstance Num a => Monoid a where mappend :: m -> m -> m mappend x y = (+) x y mempty :: m mempty = 0instance Monoid Bool where mappend :: m -> m -> m mappend True _ = True mappend _ True = True mappend _ _ = False mempty :: m
  51. 51. class Monoid m where mappend :: m -> m -> m mempty :: minstance Num a => Monoid a where mappend :: m -> m -> m mappend x y = (+) x y mempty :: m mempty = 0instance Monoid Bool where mappend :: m -> m -> m mappend True _ = True mappend _ True = True mappend _ _ = False mempty :: m
  52. 52. Haskell type signatures can . . . express side effects e.g. String -> IO Int declare computational strategies e.g. Num a => [a] -> Sum a impose constraints e.g. Num a => a -> a question value availability e.g. String -> Maybe Int verify client-server protocol dialogs? an exercise for reader ;)
  53. 53. Haskell type signatures can . . . express side effects e.g. String -> IO Int declare computational strategies e.g. Num a => [a] -> Sum a impose constraints e.g. Num a => a -> a question value availability e.g. String -> Maybe Int verify client-server protocol dialogs? an exercise for reader ;)
  54. 54. Haskell type signatures can . . . express side effects e.g. String -> IO Int declare computational strategies e.g. Num a => [a] -> Sum a impose constraints e.g. Num a => a -> a question value availability e.g. String -> Maybe Int verify client-server protocol dialogs? an exercise for reader ;)
  55. 55. Haskell type signatures can . . . express side effects e.g. String -> IO Int declare computational strategies e.g. Num a => [a] -> Sum a impose constraints e.g. Num a => a -> a question value availability e.g. String -> Maybe Int verify client-server protocol dialogs? an exercise for reader ;)
  56. 56. Haskell type signatures can . . . express side effects e.g. String -> IO Int declare computational strategies e.g. Num a => [a] -> Sum a impose constraints e.g. Num a => a -> a question value availability e.g. String -> Maybe Int verify client-server protocol dialogs? an exercise for reader ;)
  57. 57. Interfaces in OO . . . Figure: Class definitions are married to the interfaces they implement.
  58. 58. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  59. 59. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  60. 60. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  61. 61. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  62. 62. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  63. 63. Interfaces in Haskell: Typeclasses. . . Decouple type definition from interface Allow upstream implementations Extend thirdparty libraries easily Redefine implementations upstream No meaningless "any type" functions Very flexible
  64. 64. class (Eq a) => Ord a where compare :: a -> a -> Ordering compare x y | x == y = EQ | x <= y = LT | otherwise = GT (<), (>), (>=), (<=) :: a -> a -> Bool ... max, min :: a -> a -> a ...
  65. 65. Typically this just works . . . data SimpleShape = Square { size :: Double } | Circle { radius :: Double } deriving (Eq, Ord, Show) We explicitly use the default definitions. . . and when it doesn’t . . . instance Ord SimpleShape where ...
  66. 66. Are you awake? Figure: http://absolutelymadness.tumblr.com/post/18126913457
  67. 67. Haskell Tooling: Libraries Quite a few Practical libraries Often freely available Permissive OSS licenses
  68. 68. Haskell Tooling: Libraries Quite a few Practical libraries Often freely available Permissive OSS licenses
  69. 69. Haskell Tooling: Libraries Quite a few Practical libraries Often freely available Permissive OSS licenses
  70. 70. Haskell Tooling: Libraries Quite a few Practical libraries Often freely available Permissive OSS licenses
  71. 71. Haskell Tooling: Runtime Reasonably performant between JVM 7 and C# Mono performance GC settings easily customized Numerous other runtime options
  72. 72. Haskell Tooling: Runtime Reasonably performant between JVM 7 and C# Mono performance GC settings easily customized Numerous other runtime options
  73. 73. Haskell Tooling: Runtime Reasonably performant between JVM 7 and C# Mono performance GC settings easily customized Numerous other runtime options
  74. 74. Haskell Tooling: Tools Testing tools QuickCheck, HUnit Documentation tools Haddock, Hoogle (lookup documentation) Build tools Cabal, cabal-dev, cabal-nirvana, see "next slide"
  75. 75. Haskell Tooling: Tools Testing tools QuickCheck, HUnit Documentation tools Haddock, Hoogle (lookup documentation) Build tools Cabal, cabal-dev, cabal-nirvana, see "next slide"
  76. 76. Haskell Tooling: Tools Testing tools QuickCheck, HUnit Documentation tools Haddock, Hoogle (lookup documentation) Build tools Cabal, cabal-dev, cabal-nirvana, see "next slide"
  77. 77. Haskell Tooling: DependencyManagement Hackage database of freely available Haskell libraries Cabal great to get started, BUT . . . cabal-dev & similar provides sandboxing, list RVM with gemsets; more important for statically typed environments cabal-nirvana think compatible distribution snapshot of Hackage DB
  78. 78. Haskell Tooling: DependencyManagement Hackage database of freely available Haskell libraries Cabal great to get started, BUT . . . cabal-dev & similar provides sandboxing, list RVM with gemsets; more important for statically typed environments cabal-nirvana think compatible distribution snapshot of Hackage DB
  79. 79. Haskell Tooling: DependencyManagement Hackage database of freely available Haskell libraries Cabal great to get started, BUT . . . cabal-dev & similar provides sandboxing, list RVM with gemsets; more important for statically typed environments cabal-nirvana think compatible distribution snapshot of Hackage DB
  80. 80. Haskell Tooling: DependencyManagement Hackage database of freely available Haskell libraries Cabal great to get started, BUT . . . cabal-dev & similar provides sandboxing, list RVM with gemsets; more important for statically typed environments cabal-nirvana think compatible distribution snapshot of Hackage DB
  81. 81. Haskell Tooling: Don’ts for Newbies Use GHC (not HUGS) Hugs written for educational purposes not industrial usage Forget what you know (imperative/OO) relearn programming in a functional-style return is a function name it does not mean return in the C/Java/C# way class does not mean OO-class think decoupled interface with optional default impelementations and a lot more power
  82. 82. Haskell Tooling: Don’ts for Newbies Use GHC (not HUGS) Hugs written for educational purposes not industrial usage Forget what you know (imperative/OO) relearn programming in a functional-style return is a function name it does not mean return in the C/Java/C# way class does not mean OO-class think decoupled interface with optional default impelementations and a lot more power
  83. 83. Haskell Tooling: Don’ts for Newbies Use GHC (not HUGS) Hugs written for educational purposes not industrial usage Forget what you know (imperative/OO) relearn programming in a functional-style return is a function name it does not mean return in the C/Java/C# way class does not mean OO-class think decoupled interface with optional default impelementations and a lot more power
  84. 84. Haskell Tooling: Don’ts for Newbies Use GHC (not HUGS) Hugs written for educational purposes not industrial usage Forget what you know (imperative/OO) relearn programming in a functional-style return is a function name it does not mean return in the C/Java/C# way class does not mean OO-class think decoupled interface with optional default impelementations and a lot more power
  85. 85. Haskell Tooling: Suggestions Explicit language extensions Intentionally and explicitly enable per module Sandbox your builds with cabal-dev or similar Think in types and shapes and use Hoogle to lookup based on types and function "shapes"
  86. 86. Haskell Tooling: Suggestions Explicit language extensions Intentionally and explicitly enable per module Sandbox your builds with cabal-dev or similar Think in types and shapes and use Hoogle to lookup based on types and function "shapes"
  87. 87. Haskell Tooling: Suggestions Explicit language extensions Intentionally and explicitly enable per module Sandbox your builds with cabal-dev or similar Think in types and shapes and use Hoogle to lookup based on types and function "shapes"
  88. 88. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  89. 89. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  90. 90. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  91. 91. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  92. 92. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  93. 93. Oh, the possibilities! Parallel / Concurrency Options threads, dataflow, par, seq "Cloud" Haskell A kind of Erlang/OTP clone in Haskell Data Parallel Haskell GHC extensions to support nested data parallelism accounting, "Nepal" Haskell’s Foreign Function Interface (FFI) Interface with native code from Haskell GPU Programming in Haskell Obsidian, Nikola, GpuGen, numerous papers on this too Much more. . . Research meeting industrial application
  94. 94. Questions? Figure: http://www.flickr.com/photos/42682395@N04/ @SusanPotter
  95. 95. Questions? Figure: http://www.flickr.com/photos/42682395@N04/ @SusanPotter
  96. 96. Bonus: References / Resources Channel 9 Lectures (Erik Meijer) http://channel9.msdn.com/Shows/Going+Deep/ Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 Learn You A Haskell http://learnyouahaskell.com Haskell Reddit http://www.reddit.com/r/haskell/ Haskell Cafe http://www.haskell.org/mailman/listinfo/haskell-cafe Real World Haskell http://book.realworldhaskell.org/
  97. 97. Bonus: References / Resources Channel 9 Lectures (Erik Meijer) http://channel9.msdn.com/Shows/Going+Deep/ Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 Learn You A Haskell http://learnyouahaskell.com Haskell Reddit http://www.reddit.com/r/haskell/ Haskell Cafe http://www.haskell.org/mailman/listinfo/haskell-cafe Real World Haskell http://book.realworldhaskell.org/
  98. 98. Bonus: References / Resources Channel 9 Lectures (Erik Meijer) http://channel9.msdn.com/Shows/Going+Deep/ Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 Learn You A Haskell http://learnyouahaskell.com Haskell Reddit http://www.reddit.com/r/haskell/ Haskell Cafe http://www.haskell.org/mailman/listinfo/haskell-cafe Real World Haskell http://book.realworldhaskell.org/
  99. 99. Bonus: References / Resources Channel 9 Lectures (Erik Meijer) http://channel9.msdn.com/Shows/Going+Deep/ Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 Learn You A Haskell http://learnyouahaskell.com Haskell Reddit http://www.reddit.com/r/haskell/ Haskell Cafe http://www.haskell.org/mailman/listinfo/haskell-cafe Real World Haskell http://book.realworldhaskell.org/
  100. 100. Bonus: References / Resources Channel 9 Lectures (Erik Meijer) http://channel9.msdn.com/Shows/Going+Deep/ Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 Learn You A Haskell http://learnyouahaskell.com Haskell Reddit http://www.reddit.com/r/haskell/ Haskell Cafe http://www.haskell.org/mailman/listinfo/haskell-cafe Real World Haskell http://book.realworldhaskell.org/
  101. 101. Bonus: Brief QuickCheck Examplemodule Tests whereimport Test.QuickCheck (quickCheck)propReverseReverse :: [Char] -> BoolpropReverseReverse s = (reverse . reverse) s == s excuse the weird syntax form, indenting didn’t show up ;(main = do {quickCheck propReverseReverse }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×