dan johnson. functional language that started development in 1987. committee designed language ...
TRANSCRIPT
HASKELL
Dan Johnson
History in a Nutshell Functional language that started
development in 1987. Committee designed language Pure and Lazy Compiled or Interpreted Named after Haskell Curry (who has
nothing to do with the language itself)
The Goals of Haskell It should be suitable for teaching, research, and
applications, including building large systems. It should be completely described via the
publication of a formal syntax and semantics. It should be freely available. It should be usable as a basis for further language
research. It should be based on ideas that enjoy a wide
consensus. It should reduce unnecessary diversity in
functional programming languages.
Prelude Contains a large number of functions for
basic operations and list manipulation. Loaded automatically when ghci is
started
Everything has a type! Everything is considered to be “of a type”.
A functions type is determined by its return type.
The :: literally means “is of the type”. Groups of similar types are classified into
Typeclasses.
More about types! Type Inference
Haskell will evaluate the parameters to this function and determine that...
Generally considered bad practice to rely on type inference
Lists and Tuples Lists function the same way as in
Racket.
Tuples are fixed length types that can contain multiple elements of different types.
By combining lists and tuples, you can create complex and powerful data structures
F.. Functions. Two parts: declaration and definition
Line 34 uses type variables to make the function polymorphic.
Line 35 uses some of the list functions built into prelude
Curried Functions Two ways to pass multiple parameters
to a function: By using a tuple as the parameter By defining the function as a curried
function
Most multi-parameter functions are curried functions
Higher Order Functions Any function that returns a function as
its result or accepts a function as a parameter
All curried functions are Higher Order functions because their return type is technically a function
Polymorphic Functions Any function that uses type variables (and only
type variables) is considered to be a polymorphic function.
Polymorphic functions are easy to create Type inference automatically defines
polymorphic types when applicable. Allow for one function to cover a broad range of
types Most functions in the Prelude are polymorphic
functions
If .. Then .. vs GuardsIf .. Then .. Guards
Syntactically similar to most languages
No “else if” statement, must be done with nested ifs
Written more as a mathematician would write a case structure
More readable, less code to write
Recursion Is at the core of Haskell because it is so
prevalent in mathematics Simply recall the function with different
parameters in the function
Object Oriented Design
Lazy Evaluation Expressions are only evaluated as much
as required to produce the final result. What does this mean? Why is it important? Where can we use it?
Purity Pure languages are said to e languages
without side effects What is a side effect? Is a pure language even possible? What are the benefits of purity? What are the cons of purity?
Hangman