
FP 2005 1.1 3 Functional Programming WOLFRAM KAHL [email protected] Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative — “telling the machine what to do” Declarative — “telling the machine what to achieve” Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.3 5 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.4 6 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.5 7 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.6 8 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.7 9 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.8 10 What Kinds of Programming Languages are There? Imperative Ð ªtelling the machine what to doº Declarative Ð ªtelling the machine what to achieveº Programming Languages Imperative Declarative C, Pascal Functional Logic FORTRAN Object-oriented COBOL Modula-2 Haskell, OCaml Prolog ML, Scheme, LISP C++, Oberon-2 Mercury Java, Smalltalk FP 2005 1.9 11 Programming Language Paradigms Imperative Programming Languages Statement oriented languages Every statement changes the machine state Object-oriented languages Organising the state into objects with individual state and behaviour Message passing paradigm (instead of subprogram call) Rule-Based (Logical) Programming Languages Specify rule that specifies problem solution (Prolog, BNF Parsing) Other examples: Decision procedures, Grammar rules (BNF) Programming consists of specifying the attributes of the answer Functional (Applicative) Programming Languages Goal is to understand the function that produces the answer Function composition is major operation Programming consists of building the function that computes the answer FP 2005 1.10 12 Historical Development of Programming Languages FP 2005 1.11 13 Historical Development of Programming Languages Emphasis has changed: FP 2005 1.12 14 Historical Development of Programming Languages Emphasis has changed: – from making life easier for the computer FP 2005 1.13 15 Historical Development of Programming Languages Emphasis has changed: – from making life easier for the computer – to making it easier for the programmer. FP 2005 1.14 16 Historical Development of Programming Languages Emphasis has changed: ± from making life easier for the computer ± to making it easier for the programmer. Easier for the programmer means: FP 2005 1.15 17 Historical Development of Programming Languages Emphasis has changed: ± from making life easier for the computer ± to making it easier for the programmer. Easier for the programmer means: ± Use languages that facilitate writing error-free programs FP 2005 1.16 18 Historical Development of Programming Languages Emphasis has changed: ± from making life easier for the computer ± to making it easier for the programmer. Easier for the programmer means: ± Use languages that facilitate writing error-free programs ± Use languages that facilitate writing programs that are easy to maintain FP 2005 1.17 19 Historical Development of Programming Languages Emphasis has changed: ± from making life easier for the computer ± to making it easier for the programmer. Easier for the programmer means: ± Use languages that facilitate writing error-free programs ± Use languages that facilitate writing programs that are easy to maintain Goal of language development: FP 2005 1.18 20 Historical Development of Programming Languages Emphasis has changed: – from making life easier for the computer – to making it easier for the programmer. Easier for the programmer means: – Use languages that facilitate writing error-free programs – Use languages that facilitate writing programs that are easy to maintain Goal of language development: – Developers concentrate on design (or even just specification) – Programming is trivial or handled by computer (executable specification languages, rapid prototyping) FP 2005 1.19 21 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.20 22 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.21 23 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.22 24 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.23 25 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.24 26 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 1.25 27 Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML LISP, Scheme OCaml APL, J Erlang FP 2005 2.1 29 Haskell FP 2005 2.2 30 Haskell • functional FP 2005 2.3 31 Haskell • functional — programs are function definitions FP 2005 2.4 32 Haskell • functional — programs are function definitions; functions are “first-class citizens” FP 2005 2.5 33 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) FP 2005 2.6 34 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” FP 2005 2.7 35 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) FP 2005 2.8 36 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed FP 2005 2.9 37 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed • statically strongly typed FP 2005 2.10 38 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed • statically strongly typed — all type errors caught at compile-time FP 2005 2.11 39 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed • statically strongly typed — all type errors caught at compile-time • type classes — safe overloading FP 2005 2.12 40 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed • statically strongly typed — all type errors caught at compile-time • type classes — safe overloading • Standardised language version: Haskell 98 FP 2005 2.13 41 Haskell • functional — programs are function definitions; functions are “first-class citizens” • pure (referentially transparent) — “no side-effects” • non-strict (lazy) — arguments are evaluated only when needed • statically strongly typed — all type errors caught at compile-time • type classes — safe overloading • Standardised language version: Haskell 98 • Several compilers and interpreters available
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages426 Page
-
File Size-