Why Haskell
-
Upload
susan-potter -
Category
Technology
-
view
5.517 -
download
2
description
Transcript of Why Haskell
![Page 1: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/1.jpg)
Why Haskell?
Susan Potter
March 2012
![Page 2: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/2.jpg)
What is Haskell?
Figure: "pure functional, lazy, polymorphic, statically and strongly typed with type inference . . . "
![Page 3: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/3.jpg)
How can I drive this thing?
Figure: Photo from "If programming languages were cars" blog posthttp://machinegestalt.posterous.com/if-programming-languages-were-cars
![Page 4: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/4.jpg)
Can I drive Haskell without all this?
Figure: No need to know Category Theory proofs, just some intuitions!
![Page 5: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/5.jpg)
# 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 [email protected] working at Desk.com! Looking for smart developers!;)Plan:github: mbbx6spptwitter: @SusanPotter
![Page 6: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/6.jpg)
Are we "doing it wrong"?
Figure: Maybe! ;)http://absolutelymadness.tumblr.com/post/17567574522
![Page 7: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/7.jpg)
Overview: Choosing a language
Many considerationspolitical, human, technical
Runtimeperformance, reliability, configurability
Knowledgeculture, mindshare, resources, signal to noise ratio
Toolingdevelopment, build/release, configuration, deployment
![Page 8: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/8.jpg)
Overview: Choosing a language
Many considerationspolitical, human, technical
Runtimeperformance, reliability, configurability
Knowledgeculture, mindshare, resources, signal to noise ratio
Toolingdevelopment, build/release, configuration, deployment
![Page 9: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/9.jpg)
Overview: Choosing a language
Many considerationspolitical, human, technical
Runtimeperformance, reliability, configurability
Knowledgeculture, mindshare, resources, signal to noise ratio
Toolingdevelopment, build/release, configuration, deployment
![Page 10: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/10.jpg)
Overview: Choosing a language
Many considerationspolitical, human, technical
Runtimeperformance, reliability, configurability
Knowledgeculture, mindshare, resources, signal to noise ratio
Toolingdevelopment, build/release, configuration, deployment
![Page 11: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/11.jpg)
Overview: Agenda
My Claims / Hypotheses
Laziness, Functional, Type System
Toolkit & Runtime
Library Ecosystem
Pitfalls & Hurdles
![Page 12: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/12.jpg)
My Claims
Performance is reasonableon 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 benefitsafter initial steep learning curve
Haskell types offer stronger verifiabilitystrong and meaningful checks applied
Pure functional code is easier to testprobably not controversial
![Page 13: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/13.jpg)
My Claims
Performance is reasonableon 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 benefitsafter initial steep learning curve
Haskell types offer stronger verifiabilitystrong and meaningful checks applied
Pure functional code is easier to testprobably not controversial
![Page 14: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/14.jpg)
My Claims
Performance is reasonableon 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 benefitsafter initial steep learning curve
Haskell types offer stronger verifiabilitystrong and meaningful checks applied
Pure functional code is easier to testprobably not controversial
![Page 15: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/15.jpg)
My Claims
Performance is reasonableon 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 benefitsafter initial steep learning curve
Haskell types offer stronger verifiabilitystrong and meaningful checks applied
Pure functional code is easier to testprobably not controversial
![Page 16: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/16.jpg)
Haskell "lazy" by default
Figure: Photo by Mark Fischerhttp://www.flickr.com/photos/tom_ruaat/4431626234/
(jarring for mainstream programmers)
![Page 17: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/17.jpg)
Haskell "lazy" by default
Figure: Photo by Mark Fischerhttp://www.flickr.com/photos/tom_ruaat/4431626234/
(jarring for mainstream programmers)
![Page 18: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/18.jpg)
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)
![Page 19: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/19.jpg)
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)
![Page 20: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/20.jpg)
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)
![Page 21: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/21.jpg)
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)
![Page 22: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/22.jpg)
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)
![Page 23: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/23.jpg)
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)
![Page 24: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/24.jpg)
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)
![Page 25: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/25.jpg)
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)
![Page 26: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/26.jpg)
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)
![Page 27: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/27.jpg)
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)
![Page 28: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/28.jpg)
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)
![Page 29: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/29.jpg)
Laziness in Haskell is . . .
CallByName
+ SharingOptimization
+ PossibleMinorOverhead
![Page 30: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/30.jpg)
Laziness: Buyer Bewarefilter (λ x → x < 6) [1..](never terminates)
takeWhile (λ x → x < 6) [1..](does terminate)
dropWhile (λ x → x >= 6) [1..](does not terminate)
Need to understand implicationsof laziness on functions
Laziness with I/O implicationslazy 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, . . .
![Page 31: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/31.jpg)
Laziness: Buyer Bewarefilter (λ x → x < 6) [1..](never terminates)
takeWhile (λ x → x < 6) [1..](does terminate)
dropWhile (λ x → x >= 6) [1..](does not terminate)
Need to understand implicationsof laziness on functions
Laziness with I/O implicationslazy 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, . . .
![Page 32: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/32.jpg)
Laziness: Buyer Bewarefilter (λ x → x < 6) [1..](never terminates)
takeWhile (λ x → x < 6) [1..](does terminate)
dropWhile (λ x → x >= 6) [1..](does not terminate)
Need to understand implicationsof laziness on functions
Laziness with I/O implicationslazy 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, . . .
![Page 33: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/33.jpg)
Laziness: Buyer Bewarefilter (λ x → x < 6) [1..](never terminates)
takeWhile (λ x → x < 6) [1..](does terminate)
dropWhile (λ x → x >= 6) [1..](does not terminate)
Need to understand implicationsof laziness on functions
Laziness with I/O implicationslazy 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, . . .
![Page 34: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/34.jpg)
Laziness: Buyer Bewarefilter (λ x → x < 6) [1..](never terminates)
takeWhile (λ x → x < 6) [1..](does terminate)
dropWhile (λ x → x >= 6) [1..](does not terminate)
Need to understand implicationsof laziness on functions
Laziness with I/O implicationslazy 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, . . .
![Page 35: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/35.jpg)
Laziness: Also Pretty Suuweeeet!
Infinite sequences/listsmade possible
Recursive functionsbecome practical
Recursive typesbecome simple
Much more as well ...
![Page 36: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/36.jpg)
Laziness: Also Pretty Suuweeeet!
Infinite sequences/listsmade possible
Recursive functionsbecome practical
Recursive typesbecome simple
Much more as well ...
![Page 37: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/37.jpg)
Laziness: Also Pretty Suuweeeet!
Infinite sequences/listsmade possible
Recursive functionsbecome practical
Recursive typesbecome simple
Much more as well ...
![Page 38: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/38.jpg)
Laziness: Also Pretty Suuweeeet!
Infinite sequences/listsmade possible
Recursive functionsbecome practical
Recursive typesbecome simple
Much more as well ...
![Page 39: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/39.jpg)
Purity + Laziness=> Reasoning
Equality (referential transparency)Can replace occurrences of LHS with RHS
Higher Order Functionsencourage exploitation of higher-level patterns
Function Compositionleads to greater reuse
![Page 40: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/40.jpg)
Purity + Laziness=> Reasoning
Equality (referential transparency)Can replace occurrences of LHS with RHS
Higher Order Functionsencourage exploitation of higher-level patterns
Function Compositionleads to greater reuse
![Page 41: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/41.jpg)
Purity + Laziness=> Reasoning
Equality (referential transparency)Can replace occurrences of LHS with RHS
Higher Order Functionsencourage exploitation of higher-level patterns
Function Compositionleads to greater reuse
![Page 42: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/42.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 43: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/43.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 44: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/44.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 45: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/45.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 46: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/46.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 47: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/47.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 48: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/48.jpg)
mysum :: Num a => [a] -> amysum xs = foldr (+) 0 xs
myproduct :: Num a => [a] -> amyproduct xs = foldr (*) 1 xs
myany :: (a -> Bool) -> [a] -> Boolmyany pred xs = foldr (\ x b -> b || pred x) False xs
myall :: (a -> Bool) -> [a] -> Boolmyall pred xs = foldr (\ x b -> b && pred x) True xs
![Page 49: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/49.jpg)
class Monoid m wheremappend :: m -> m -> mmempty :: m
instance Num a => Monoid a wheremappend :: m -> m -> mmappend x y = (+) x ymempty :: mmempty = 0
instance Monoid Bool wheremappend :: m -> m -> mmappend True _ = Truemappend _ True = Truemappend _ _ = Falsemempty :: mmempty = False
![Page 50: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/50.jpg)
class Monoid m wheremappend :: m -> m -> mmempty :: m
instance Num a => Monoid a wheremappend :: m -> m -> mmappend x y = (+) x ymempty :: mmempty = 0
instance Monoid Bool wheremappend :: m -> m -> mmappend True _ = Truemappend _ True = Truemappend _ _ = Falsemempty :: mmempty = False
![Page 51: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/51.jpg)
class Monoid m wheremappend :: m -> m -> mmempty :: m
instance Num a => Monoid a wheremappend :: m -> m -> mmappend x y = (+) x ymempty :: mmempty = 0
instance Monoid Bool wheremappend :: m -> m -> mmappend True _ = Truemappend _ True = Truemappend _ _ = Falsemempty :: mmempty = False
![Page 52: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/52.jpg)
Haskell type signatures can . . .
express side effectse.g. String -> IO Int
declare computational strategiese.g. Num a => [a] -> Sum a
impose constraintse.g. Num a => a -> a
question value availabilitye.g. String -> Maybe Int
verify client-server protocol dialogs?an exercise for reader ;)
![Page 53: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/53.jpg)
Haskell type signatures can . . .
express side effectse.g. String -> IO Int
declare computational strategiese.g. Num a => [a] -> Sum a
impose constraintse.g. Num a => a -> a
question value availabilitye.g. String -> Maybe Int
verify client-server protocol dialogs?an exercise for reader ;)
![Page 54: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/54.jpg)
Haskell type signatures can . . .
express side effectse.g. String -> IO Int
declare computational strategiese.g. Num a => [a] -> Sum a
impose constraintse.g. Num a => a -> a
question value availabilitye.g. String -> Maybe Int
verify client-server protocol dialogs?an exercise for reader ;)
![Page 55: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/55.jpg)
Haskell type signatures can . . .
express side effectse.g. String -> IO Int
declare computational strategiese.g. Num a => [a] -> Sum a
impose constraintse.g. Num a => a -> a
question value availabilitye.g. String -> Maybe Int
verify client-server protocol dialogs?an exercise for reader ;)
![Page 56: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/56.jpg)
Haskell type signatures can . . .
express side effectse.g. String -> IO Int
declare computational strategiese.g. Num a => [a] -> Sum a
impose constraintse.g. Num a => a -> a
question value availabilitye.g. String -> Maybe Int
verify client-server protocol dialogs?an exercise for reader ;)
![Page 57: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/57.jpg)
Interfaces in OO . . .
Figure: Class definitions are married to the interfaces they implement.
![Page 58: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/58.jpg)
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
![Page 59: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/59.jpg)
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
![Page 60: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/60.jpg)
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
![Page 61: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/61.jpg)
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
![Page 62: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/62.jpg)
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
![Page 63: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/63.jpg)
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
![Page 64: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/64.jpg)
class (Eq a) => Ord a wherecompare :: a -> a -> Orderingcompare x y | x == y = EQ
| x <= y = LT| otherwise = GT
(<), (>), (>=), (<=) :: a -> a -> Bool...max, min :: a -> a -> a...
![Page 65: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/65.jpg)
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...
![Page 66: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/66.jpg)
Are you awake?
Figure: http://absolutelymadness.tumblr.com/post/18126913457
![Page 67: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/67.jpg)
Haskell Tooling: Libraries
Quite a few
Practical libraries
Often freely available
Permissive OSS licenses
![Page 68: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/68.jpg)
Haskell Tooling: Libraries
Quite a few
Practical libraries
Often freely available
Permissive OSS licenses
![Page 69: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/69.jpg)
Haskell Tooling: Libraries
Quite a few
Practical libraries
Often freely available
Permissive OSS licenses
![Page 70: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/70.jpg)
Haskell Tooling: Libraries
Quite a few
Practical libraries
Often freely available
Permissive OSS licenses
![Page 71: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/71.jpg)
Haskell Tooling: Runtime
Reasonably performantbetween JVM 7 and C# Mono performance
GC settings easily customized
Numerous other runtime options
![Page 72: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/72.jpg)
Haskell Tooling: Runtime
Reasonably performantbetween JVM 7 and C# Mono performance
GC settings easily customized
Numerous other runtime options
![Page 73: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/73.jpg)
Haskell Tooling: Runtime
Reasonably performantbetween JVM 7 and C# Mono performance
GC settings easily customized
Numerous other runtime options
![Page 74: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/74.jpg)
Haskell Tooling: Tools
Testing toolsQuickCheck, HUnit
Documentation toolsHaddock, Hoogle (lookup documentation)
Build toolsCabal, cabal-dev, cabal-nirvana, see "next slide"
![Page 75: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/75.jpg)
Haskell Tooling: Tools
Testing toolsQuickCheck, HUnit
Documentation toolsHaddock, Hoogle (lookup documentation)
Build toolsCabal, cabal-dev, cabal-nirvana, see "next slide"
![Page 76: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/76.jpg)
Haskell Tooling: Tools
Testing toolsQuickCheck, HUnit
Documentation toolsHaddock, Hoogle (lookup documentation)
Build toolsCabal, cabal-dev, cabal-nirvana, see "next slide"
![Page 77: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/77.jpg)
Haskell Tooling: DependencyManagement
Hackagedatabase of freely available Haskell libraries
Cabalgreat to get started, BUT . . .
cabal-dev & similarprovides sandboxing, list RVM with gemsets; more important for statically typed environments
cabal-nirvanathink compatible distribution snapshot of Hackage DB
![Page 78: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/78.jpg)
Haskell Tooling: DependencyManagement
Hackagedatabase of freely available Haskell libraries
Cabalgreat to get started, BUT . . .
cabal-dev & similarprovides sandboxing, list RVM with gemsets; more important for statically typed environments
cabal-nirvanathink compatible distribution snapshot of Hackage DB
![Page 79: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/79.jpg)
Haskell Tooling: DependencyManagement
Hackagedatabase of freely available Haskell libraries
Cabalgreat to get started, BUT . . .
cabal-dev & similarprovides sandboxing, list RVM with gemsets; more important for statically typed environments
cabal-nirvanathink compatible distribution snapshot of Hackage DB
![Page 80: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/80.jpg)
Haskell Tooling: DependencyManagement
Hackagedatabase of freely available Haskell libraries
Cabalgreat to get started, BUT . . .
cabal-dev & similarprovides sandboxing, list RVM with gemsets; more important for statically typed environments
cabal-nirvanathink compatible distribution snapshot of Hackage DB
![Page 81: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/81.jpg)
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 nameit does not mean return in the C/Java/C# way
class does not mean OO-classthink decoupled interface with optional default impelementations and a lot more power
![Page 82: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/82.jpg)
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 nameit does not mean return in the C/Java/C# way
class does not mean OO-classthink decoupled interface with optional default impelementations and a lot more power
![Page 83: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/83.jpg)
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 nameit does not mean return in the C/Java/C# way
class does not mean OO-classthink decoupled interface with optional default impelementations and a lot more power
![Page 84: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/84.jpg)
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 nameit does not mean return in the C/Java/C# way
class does not mean OO-classthink decoupled interface with optional default impelementations and a lot more power
![Page 85: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/85.jpg)
Haskell Tooling: Suggestions
Explicit language extensionsIntentionally and explicitly enable per module
Sandbox your buildswith cabal-dev or similar
Think in types and shapesand use Hoogle to lookup based on types and function "shapes"
![Page 86: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/86.jpg)
Haskell Tooling: Suggestions
Explicit language extensionsIntentionally and explicitly enable per module
Sandbox your buildswith cabal-dev or similar
Think in types and shapesand use Hoogle to lookup based on types and function "shapes"
![Page 87: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/87.jpg)
Haskell Tooling: Suggestions
Explicit language extensionsIntentionally and explicitly enable per module
Sandbox your buildswith cabal-dev or similar
Think in types and shapesand use Hoogle to lookup based on types and function "shapes"
![Page 88: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/88.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 89: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/89.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 90: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/90.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 91: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/91.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 92: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/92.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 93: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/93.jpg)
Oh, the possibilities!Parallel / Concurrency Optionsthreads, dataflow, par, seq
"Cloud" HaskellA kind of Erlang/OTP clone in Haskell
Data Parallel HaskellGHC extensions to support nested data parallelism accounting, "Nepal"
Haskell’s Foreign Function Interface (FFI)Interface with native code from Haskell
GPU Programming in HaskellObsidian, Nikola, GpuGen, numerous papers on this too
Much more. . .Research meeting industrial application
![Page 94: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/94.jpg)
Questions?
Figure: http://www.flickr.com/photos/42682395@N04/
@SusanPotter
![Page 95: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/95.jpg)
Questions?
Figure: http://www.flickr.com/photos/42682395@N04/
@SusanPotter
![Page 96: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/96.jpg)
Bonus: References / ResourcesChannel 9 Lectures (Erik Meijer)http://channel9.msdn.com/Shows/Going+Deep/
Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1
Learn You A Haskellhttp://learnyouahaskell.com
Haskell Reddithttp://www.reddit.com/r/haskell/
Haskell Cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe
Real World Haskellhttp://book.realworldhaskell.org/
![Page 97: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/97.jpg)
Bonus: References / ResourcesChannel 9 Lectures (Erik Meijer)http://channel9.msdn.com/Shows/Going+Deep/
Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1
Learn You A Haskellhttp://learnyouahaskell.com
Haskell Reddithttp://www.reddit.com/r/haskell/
Haskell Cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe
Real World Haskellhttp://book.realworldhaskell.org/
![Page 98: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/98.jpg)
Bonus: References / ResourcesChannel 9 Lectures (Erik Meijer)http://channel9.msdn.com/Shows/Going+Deep/
Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1
Learn You A Haskellhttp://learnyouahaskell.com
Haskell Reddithttp://www.reddit.com/r/haskell/
Haskell Cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe
Real World Haskellhttp://book.realworldhaskell.org/
![Page 99: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/99.jpg)
Bonus: References / ResourcesChannel 9 Lectures (Erik Meijer)http://channel9.msdn.com/Shows/Going+Deep/
Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1
Learn You A Haskellhttp://learnyouahaskell.com
Haskell Reddithttp://www.reddit.com/r/haskell/
Haskell Cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe
Real World Haskellhttp://book.realworldhaskell.org/
![Page 100: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/100.jpg)
Bonus: References / ResourcesChannel 9 Lectures (Erik Meijer)http://channel9.msdn.com/Shows/Going+Deep/
Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1
Learn You A Haskellhttp://learnyouahaskell.com
Haskell Reddithttp://www.reddit.com/r/haskell/
Haskell Cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe
Real World Haskellhttp://book.realworldhaskell.org/
![Page 101: Why Haskell](https://reader034.fdocuments.in/reader034/viewer/2022042518/53ffe21c8d7f7249088b475e/html5/thumbnails/101.jpg)
Bonus: Brief QuickCheck Example
module Tests where
import 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 }