Why Haskell

Download Why Haskell

Post on 29-Aug-2014

5.502 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

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 is 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!

TRANSCRIPT

<ul><li> Why Haskell? Susan Potter March 2012 </li> <li> What is Haskell? Figure: "pure functional, lazy, polymorphic, statically and strongly typed with type inference . . . " </li> <li> 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 </li> <li> Can I drive Haskell without all this? Figure: No need to know Category Theory proofs, just some intuitions! </li> <li> # 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 </li> <li> Are we "doing it wrong"? Figure: Maybe! ;) http://absolutelymadness.tumblr.com/post/17567574522 </li> <li> Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, congurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, conguration, deployment </li> <li> Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, congurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, conguration, deployment </li> <li> Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, congurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, conguration, deployment </li> <li> Overview: Choosing a language Many considerations political, human, technical Runtime performance, reliability, congurability Knowledge culture, mindshare, resources, signal to noise ratio Tooling development, build/release, conguration, deployment </li> <li> Overview: Agenda My Claims / Hypotheses Laziness, Functional, Type System Toolkit &amp; Runtime Library Ecosystem Pitfalls &amp; Hurdles </li> <li> 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 benets after initial steep learning curve Haskell types offer stronger veriability strong and meaningful checks applied Pure functional code is easier to test probably not controversial </li> <li> 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 benets after initial steep learning curve Haskell types offer stronger veriability strong and meaningful checks applied Pure functional code is easier to test probably not controversial </li> <li> 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 benets after initial steep learning curve Haskell types offer stronger veriability strong and meaningful checks applied Pure functional code is easier to test probably not controversial </li> <li> 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 benets after initial steep learning curve Haskell types offer stronger veriability strong and meaningful checks applied Pure functional code is easier to test probably not controversial </li> <li> Haskell "lazy" by default Figure: Photo by Mark Fischer http://www.flickr.com/photos/tom_ruaat/4431626234/ </li> <li> Haskell "lazy" by default Figure: Photo by Mark Fischer http://www.flickr.com/photos/tom_ruaat/4431626234/ (jarring for mainstream programmers) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> 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 -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions rst) doubleSum 3 (2 + 3) doubleSum 3 5 2 * (3 + 5) 2 * 8 16 Call by name doubleSum 3 (2 + 3) ( x -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions rst) doubleSum 3 (2 + 3) doubleSum 3 5 2 * (3 + 5) 2 * 8 16 Call by name doubleSum 3 (2 + 3) ( x -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions rst) doubleSum 3 (2 + 3) doubleSum 3 5 2 * (3 + 5) 2 * 8 16 Call by name doubleSum 3 (2 + 3) ( x -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions rst) doubleSum 3 (2 + 3) doubleSum 3 5 2 * (3 + 5) 2 * 8 16 Call by name doubleSum 3 (2 + 3) ( x -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Example: doubleSum 3 (2 + 3) Call by value (evaluates inner-most expressions rst) doubleSum 3 (2 + 3) doubleSum 3 5 2 * (3 + 5) 2 * 8 16 Call by name (evaluates outer-most expressions rst) doubleSum 3 (2 + 3) ( x -&gt; 2 * (3 + x)) (2 + 3) </li> <li> Laziness in Haskell is . . . CallByName + SharingOptimization + PossibleMinorOverhead </li> <li> Laziness: Buyer Beware filter ( x x &lt; 6) [1..] (never terminates) takeWhile ( x x &lt; 6) [1..] (does terminate) dropWhile ( x x &gt;= 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, . . . </li> <li> Laziness: Buyer Beware filter ( x x &lt; 6) [1..] (never terminates) takeWhile ( x x &lt; 6) [1..] (does terminate) dropWhile ( x x &gt;= 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, . . . </li> <li> Laziness: Buyer Beware filter ( x x &lt; 6) [1..] (never terminates) takeWhile ( x x &lt; 6) [1..] (does terminate) dropWhile ( x x &gt;= 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, . . . </li> <li> Laziness: Buyer Beware filter ( x x &lt; 6) [1..] (never terminates) takeWhile ( x x &lt; 6) [1..] (does terminate) dropWhile ( x x &gt;= 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, . . . </li> <li> Laziness: Buyer Beware filter ( x x &lt; 6) [1..] (never terminates) takeWhile ( x x &lt; 6) [1..] (does terminate) dropWhile ( x x &gt;= 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, . . . </li> <li> Laziness: Also Pretty Suuweeeet! Innite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ... </li> <li> Laziness: Also Pretty Suuweeeet! Innite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ... </li> <li> Laziness: Also Pretty Suuweeeet! Innite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ... </li> <li> Laziness: Also Pretty Suuweeeet! Innite sequences/lists made possible Recursive functions become practical Recursive types become simple Much more as well ... </li> <li> Purity + Laziness=&gt; 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 </li> <li> Purity + Laziness=&gt; 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 </li> <li> Purity + Laziness=&gt; 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 </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+) 0 xsmyproduct :: Num a =&gt; [a] -&gt; amyproduct xs = foldr (*) 1 xsmyany :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyany pred xs = foldr ( x b -&gt; b || pred x) False xsmyall :: (a -&gt; Bool) -&gt; [a] -&gt; Boolmyall pred xs = foldr ( x b -&gt; b &amp;&amp; pred x) True xs </li> <li> mysum :: Num a =&gt; [a] -&gt; amysum xs = foldr (+...</li></ul>