dan johnson. functional language that started development in 1987. committee designed language ...

17
HASKELL Dan Johnson

Upload: gwen-blake

Post on 31-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

HASKELL

Dan Johnson

Page 2: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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)

Page 3: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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.

Page 4: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

Prelude Contains a large number of functions for

basic operations and list manipulation. Loaded automatically when ghci is

started

Page 5: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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.

Page 6: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 7: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 8: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 9: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 10: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 11: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 12: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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

Page 13: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

Recursion Is at the core of Haskell because it is so

prevalent in mathematics Simply recall the function with different

parameters in the function

Page 14: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

Object Oriented Design

Page 15: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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?

Page 16: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

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?

Page 17: Dan Johnson.  Functional language that started development in 1987.  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after

Hangman