Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Haskell in the Real World by osfameron 2664 views
- Haskell Tour (Part 1) by William Taysom 4912 views
- Fun never stops. introduction to ha... by Pawel Szulc 462 views
- Real World Haskell: Lecture 1 by Bryan O'Sullivan 3203 views
- Introduction to Functional Programm... by Will Kurt 5109 views
- The other side of functional progra... by Bryan O'Sullivan 6378 views

1,126 views

929 views

929 views

Published on

Presentation about Haskell.

No Downloads

Total views

1,126

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

23

Comments

0

Likes

1

No embeds

No notes for slide

- 1. Haskell being lazy with class Tiago Babo PPRO@FEUP 2012
- 2. HistoryLisp/Scheme ML/OCaml Miranda Haskell 98 1959 1979 1985 2003 functional static lazy language typing evaluation
- 3. HistoryThere are two main Haskell implementations:▹ GHC. Probably the most popular, compiles to native code on anumber of different architectures.▹ Hugs. It’s a bytecode interpreter and the most portable andlightweight of the Haskell implementations.
- 4. Related languagesThere are some languages inspired by Haskell:▹ Different type system: Epigram, Agda.▹ JVM-based: Frege, Jaskell.▹ Other related languages: Curry.▹ Testbed for many new ideas: Parallel Haskell, Eager Haskell,Generic Haskell, O’Haskell, Hume, Scotch, Disciple...
- 5. haskellHaskell is a pure functional language. It means that:▹ Variables never change after deﬁnition.▹ Functions don’t have side effects.▹ Functions always return the same output given the same input.
- 6. haskellWhat haskell offer to the programmer?▹ Purity. It doesn’t allow any side-effects.▹ Laziness (non-strict). Nothing is evaluated until it has to be evaluated.▹ Strong static typing. The compiler automatically infers a precise type forall values and it permits no implicit type conversions.▹ Elegance. Stuff just work like you’d expect it to.
- 7. haskell and bugsHaskell programs have fewer bugs because Haskell is:▹ Pure. There are no side effects.▹ Strongly typed. There can be no dubious use of types.▹ Concise. Programs are shorter which make it easier to “take it all” at once.
- 8. haskell and bugsHaskell programs have fewer bugs because Haskell is:▹ High Level. Haskell programs most often reads out almost exactly like thealgorithm description.▹ Memory Managed. There’s no worrying about dangling pointers, theGarbage Collector takes care of all that.▹ Modular. Haskell offers stronger and more “glue” to compose yourprogram from already developed modules.
- 9. haskell consHaskell has some disadvantages:▹ Hard to learn and master. It’s even harder without a proper computerscience background.▹ You can’t write haskell-like code in other programming languages.▹ Lacks libraries and support from who mantain and improve them.
- 10. code examples
- 11. ﬁbonacci1 1 2 3 5 8 13 21 34 ..
- 12. JavaList <int> fib(int i) { List <int> seq = new ArrayList(n); seq[0] = 1; seq[1] = 1; for(int i = 2; i < n; i++) { seq[i] = seq[i-2] + seq[i-1]; } return seq;}
- 13. Haskellfib = 1:1:zipWith (+) fib (tail fib)
- 14. Java VS haskellfib = 1:1:zipWith (+) fib (tail fib)List <int> seq = new ArrayList(n);seq[0] = 1;seq[1] = 1;for(int i = 2; i < n; i++) { seq[i] = seq[i-2] + seq[i-1];}
- 15. Java VS haskellfib = 1:1:zipWith (+) fib (tail fib)List <int> seq = new ArrayList(n);seq[0] = 1;seq[1] = 1;for(int i = 2; i < n; i++) { seq[i] = seq[i-2] + seq[i-1];}
- 16. Java VS haskellfib = 1:1:zipWith (+) fib (tail fib)List <int> seq = new ArrayList(n);seq[0] = 1;seq[1] = 1;for(int i = 2; i < n; i++) { seq[i] = seq[i-2] + seq[i-1];}
- 17. Java VS haskellfib = 1:1:zipWith (+) fib (tail fib)List <int> seq = new ArrayList(n);seq[0] = 1;seq[1] = 1;for(int i = 2; i < n; i++) { seq[i] = seq[i-2] + seq[i-1];}
- 18. How it works?fib = 1:1:zipWith (+) fib (tail fib)take 2 fib -> ? lazy evaluationfib = 1 : 1 : ..tail fib = 1 : ..zipWith (+) fib (tail fib) = ..take 2 fib -> [1,1]
- 19. How it works?fib = 1:1:zipWith (+) fib (tail fib)take 3 fib -> ?fib = 1 : 1 : 2 : ..tail fib = 1 : 2 : ..zipWith (+) fib (tail fib) = 2 : ..take 3 fib -> [1,1,2]
- 20. How it works?fib = 1:1:zipWith (+) fib (tail fib)take 10 fib -> ?fib = 1 : 1 : 2 : 3 : ..tail fib = 1 : 2 : 3 : ..zipWith (+) fib (tail fib) = 2 : 3 : .....fib = 1 : 1 : 2 : 3 : 5 ..tail fib = 1 : 2 : 3 : 5 : ..zipWith (+) fib (tail fib) = 2 : 3 : 5 : ..take 10 fib -> [1,1,2,3,5,8,13,21,34,55]
- 21. and how about the types?fib = 1:1:zipWith (+) fib (tail fib)
- 22. and how about the types? intfib = 1:1:zipWith (+) fib (tail fib)int
- 23. and how about the types? List<int> intfib = 1:1:zipWith (+) fib (tail fib)int
- 24. and how about the types? List<int> List<int> intfib = 1:1:zipWith (+) fib (tail fib)int List<int>
- 25. and how about the types? List<int> List<int> List<int> intfib = 1:1:zipWith (+) fib (tail fib)int List<int>
- 26. Quicksort[3,2,1,4] -> [1,2,3,4]
- 27. C// To sort array a[] of size n: qsort(a,0,n-1)void qsort(int a[], int lo, int hi){ int h, l, p, t; if (lo < hi) { l = lo; h = hi; p = a[hi]; do { while ((l < h) && (a[l] <= p)) l = l+1; while ((h > l) && (a[h] >= p)) h = h-1; if (l < h) { t = a[l]; a[l] = a[h]; a[h] = t; } } while (l < h); a[hi] = a[l]; a[l] = p; qsort( a, lo, l-1 ); qsort( a, l+1, hi ); }}
- 28. Haskellqsort(p:xs) = (qsort lesser) ++ [p] ++ (qsort greater) where lesser = filter (< p) xs greater = filter (>= p) xs
- 29. Haskellqsort(p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]
- 30. Factorial5! = 1x2x3x4x5
- 31. Haskellpatternmatching fac 0 = 1 fac n | n > 0 = n * fac (n-1) fac n = product [1..n] fac n = foldr1 (*) [1..n] fac n = if n == 1 then 1 else n * fac (n-1)
- 32. Haskellfac n = case n of 0 -> 1 n -> n * fac (n-1)facs = scanl (*) 1 [1..]fac n = facs !! n
- 33. haskell in industryHaskell is used in many areas:▹ Aerospace, defense, ﬁnance, web startups, and hardware designﬁrms.
- 34. haskell in industry automate processing procedural city generationof internet abuse complaints and simulation market programmatically analysis of cryptographicmanipulating a PHP code base protocols
- 35. haskell in industrymeasure the counterparty risk on implement mathematical portfolios of ﬁnancial derivates models and other complex job scheduling and brand handwriting recognition matching system
- 36. Haskell being lazy with classLinks:http://haskell.org/ - Haskell ofﬁcial homepagehttp://youtu.be/cXY4fSA7DnM - Stanford Tutorialhttp://haifux.org/lectures/173/ - An overview of Haskell (Haggai Eran)http://en.wikipedia.org/wiki/Haskell_(programming_language) - Haskell History Tiago Babo PPRO@FEUP 2012

No public clipboards found for this slide

Be the first to comment