SlideShare a Scribd company logo
Haskell
 being lazy with class


                         Tiago Babo
                         PPRO@FEUP 2012
History

Lisp/Scheme   ML/OCaml    Miranda     Haskell 98
    1959        1979       1985         2003
 functional     static      lazy
  language     typing    evaluation
History
There are two main Haskell implementations:

▹ GHC. Probably the most popular, compiles to native code on a
number of different architectures.

▹ Hugs. It’s a bytecode interpreter and the most portable and
lightweight of the Haskell implementations.
Related languages
There 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...
haskell
Haskell is a pure functional language. It means that:

▹ Variables never change after definition.

▹ Functions don’t have side effects.

▹ Functions always return the same output given the same input.
haskell
What 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 for
all values and it permits no implicit type conversions.

▹ Elegance. Stuff just work like you’d expect it to.
haskell and bugs
Haskell 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.
haskell and bugs
Haskell programs have fewer bugs because Haskell is:

▹ High Level. Haskell programs most often reads out almost exactly like the
algorithm description.

▹ Memory Managed. There’s no worrying about dangling pointers, the
Garbage Collector takes care of all that.

▹ Modular. Haskell offers stronger and more “glue” to compose your
program from already developed modules.
haskell cons
Haskell has some disadvantages:

▹ Hard to learn and master. It’s even harder without a proper computer
science background.

▹ You can’t write haskell-like code in other programming languages.

▹ Lacks libraries and support from who mantain and improve them.
code examples
fibonacci
1 1 2 3 5 8 13 21 34 ..
Java
List <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;
}
Haskell


fib = 1:1:zipWith (+) fib (tail fib)
Java VS haskell
fib = 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];
}
Java VS haskell
fib = 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];
}
Java VS haskell
fib = 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];
}
Java VS haskell
fib = 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];
}
How it works?
fib = 1:1:zipWith (+) fib (tail fib)



take 2 fib -> ?                             lazy evaluation
fib                          = 1 : 1 : ..
tail fib                     = 1 : ..
zipWith (+) fib (tail fib)   = ..

take 2 fib -> [1,1]
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]
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]
and how about the types?


fib = 1:1:zipWith (+) fib (tail fib)
and how about the types?
           int

fib = 1:1:zipWith (+) fib (tail fib)

int
and how about the types?
      List<int>   int

fib = 1:1:zipWith (+) fib (tail fib)

int
and how about the types?
                                    List<int>
      List<int>   int

fib = 1:1:zipWith (+) fib (tail fib)

int                     List<int>
and how about the types?
                                List<int>   List<int>
      List<int>   int

fib = 1:1:zipWith (+) fib (tail fib)

int                     List<int>
Quicksort
[3,2,1,4] -> [1,2,3,4]
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 );
  }
}
Haskell
qsort(p:xs) = (qsort lesser) ++ [p] ++
              (qsort greater)
 where
     lesser = filter (< p) xs
     greater = filter (>= p) xs
Haskell

qsort(p:xs) = qsort [x | x<-xs, x<p]
              ++ [p]
              ++ qsort [x | x<-xs, x>=p]
Factorial
5! = 1x2x3x4x5
Haskell
pattern
matching 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)
Haskell
fac n = case n of
 0 -> 1
 n -> n * fac (n-1)

facs = scanl (*) 1 [1..]

fac n = facs !! n
haskell in industry
Haskell is used in many areas:

▹ Aerospace, defense, finance, web startups, and hardware design
firms.
haskell in industry

     automate processing       procedural city generation
of internet abuse complaints     and simulation market




     programmatically          analysis of cryptographic
manipulating a PHP code base           protocols
haskell in industry

measure the counterparty risk on    implement mathematical
 portfolios of financial derivates   models and other complex




   job scheduling and brand          handwriting recognition
           matching                         system
Haskell
                         being lazy with class

Links:
http://haskell.org/ - Haskell official homepage
http://youtu.be/cXY4fSA7DnM - Stanford Tutorial
http://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

More Related Content

What's hot

Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
kyleburton
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
Ankur Gupta
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
Andrei Solntsev
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
chenge2k
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
John De Goes
 
Functional programming in java
Functional programming in javaFunctional programming in java
Functional programming in java
John Ferguson Smart Limited
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
José Paumard
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
There's a Prolog in your Scala!
There's a Prolog in your Scala!There's a Prolog in your Scala!
There's a Prolog in your Scala!
George Leontiev
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
priort
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
jonycse
 
Functional Programming and Ruby
Functional Programming and RubyFunctional Programming and Ruby
Functional Programming and Ruby
Pat Shaughnessy
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
Max Klymyshyn
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
Bryan O'Sullivan
 
Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)
Kaunas Java User Group
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
djspiewak
 
Python
PythonPython
Python
Wei-Bo Chen
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 

What's hot (20)

Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Functional programming in java
Functional programming in javaFunctional programming in java
Functional programming in java
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
There's a Prolog in your Scala!
There's a Prolog in your Scala!There's a Prolog in your Scala!
There's a Prolog in your Scala!
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Functional Programming and Ruby
Functional Programming and RubyFunctional Programming and Ruby
Functional Programming and Ruby
 
Odessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and PythonOdessapy2013 - Graph databases and Python
Odessapy2013 - Graph databases and Python
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
 
Python
PythonPython
Python
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 

Similar to Haskell - Being lazy with class

Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
romanandreg
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
Sergio Gil
 
Haskell
HaskellHaskell
Pure Laziness: An Exploration of Haskell
Pure Laziness: An Exploration of HaskellPure Laziness: An Exploration of Haskell
Pure Laziness: An Exploration of Haskell
Mitchell Vitez
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
osfameron
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
chriseidhof
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
Dmitri Nesteruk
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
Prashant Kalkar
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
Bryan O'Sullivan
 
Scala introduction
Scala introductionScala introduction
Scala introduction
Yardena Meymann
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳
Yuri Inoue
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash course
Holden Karau
 
Haskell
HaskellHaskell
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
Yodalee
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
Jongsoo Lee
 
Music as data
Music as dataMusic as data
Music as data
John Vlachoyiannis
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languages
suthi
 

Similar to Haskell - Being lazy with class (20)

Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Haskell
HaskellHaskell
Haskell
 
Pure Laziness: An Exploration of Haskell
Pure Laziness: An Exploration of HaskellPure Laziness: An Exploration of Haskell
Pure Laziness: An Exploration of Haskell
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash course
 
Haskell
HaskellHaskell
Haskell
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Music as data
Music as dataMusic as data
Music as data
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languages
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 

Haskell - Being lazy with class

  • 1. Haskell being lazy with class Tiago Babo PPRO@FEUP 2012
  • 2. History Lisp/Scheme ML/OCaml Miranda Haskell 98 1959 1979 1985 2003 functional static lazy language typing evaluation
  • 3. History There are two main Haskell implementations: ▹ GHC. Probably the most popular, compiles to native code on a number of different architectures. ▹ Hugs. It’s a bytecode interpreter and the most portable and lightweight of the Haskell implementations.
  • 4. Related languages There 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. haskell Haskell is a pure functional language. It means that: ▹ Variables never change after definition. ▹ Functions don’t have side effects. ▹ Functions always return the same output given the same input.
  • 6. haskell What 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 for all values and it permits no implicit type conversions. ▹ Elegance. Stuff just work like you’d expect it to.
  • 7. haskell and bugs Haskell 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 bugs Haskell programs have fewer bugs because Haskell is: ▹ High Level. Haskell programs most often reads out almost exactly like the algorithm description. ▹ Memory Managed. There’s no worrying about dangling pointers, the Garbage Collector takes care of all that. ▹ Modular. Haskell offers stronger and more “glue” to compose your program from already developed modules.
  • 9. haskell cons Haskell has some disadvantages: ▹ Hard to learn and master. It’s even harder without a proper computer science background. ▹ You can’t write haskell-like code in other programming languages. ▹ Lacks libraries and support from who mantain and improve them.
  • 11. fibonacci 1 1 2 3 5 8 13 21 34 ..
  • 12. Java List <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. Haskell fib = 1:1:zipWith (+) fib (tail fib)
  • 14. Java VS haskell fib = 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 haskell fib = 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 haskell fib = 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 haskell fib = 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 evaluation fib = 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? int fib = 1:1:zipWith (+) fib (tail fib) int
  • 23. and how about the types? List<int> int fib = 1:1:zipWith (+) fib (tail fib) int
  • 24. and how about the types? List<int> List<int> int fib = 1:1:zipWith (+) fib (tail fib) int List<int>
  • 25. and how about the types? List<int> List<int> List<int> int fib = 1:1:zipWith (+) fib (tail fib) int List<int>
  • 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. Haskell qsort(p:xs) = (qsort lesser) ++ [p] ++ (qsort greater) where lesser = filter (< p) xs greater = filter (>= p) xs
  • 29. Haskell qsort(p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]
  • 31. Haskell pattern matching 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. Haskell fac n = case n of 0 -> 1 n -> n * fac (n-1) facs = scanl (*) 1 [1..] fac n = facs !! n
  • 33. haskell in industry Haskell is used in many areas: ▹ Aerospace, defense, finance, web startups, and hardware design firms.
  • 34. haskell in industry automate processing procedural city generation of internet abuse complaints and simulation market programmatically analysis of cryptographic manipulating a PHP code base protocols
  • 35. haskell in industry measure the counterparty risk on implement mathematical portfolios of financial derivates models and other complex job scheduling and brand handwriting recognition matching system
  • 36. Haskell being lazy with class Links: http://haskell.org/ - Haskell official homepage http://youtu.be/cXY4fSA7DnM - Stanford Tutorial http://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