Functional programming: an alternative paradigm
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
an emphasis on expressions (with values) rather than statements/commands (which have effects on the state); plus, the use of higher-order functions |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
some functional languages (Scheme, ML) allow side-effects, but still encourage a style which depends on them as little as possible |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
in Scheme (descended from LISP), syntax is uniform and simplistic, so that programs can be encoded as data |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
|
| Higher-order functions
functions which take functions as arguments and return functions as results |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
|
| Higher-order functions
|
| Static versus dynamic typing
static typing provides security (compile-time error checking), but limits flexibility (e.g., no reflection/reification as in Scheme) |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
|
| Higher-order functions
|
| Static versus dynamic typing
|
| Polymorphic types
we can allow more flexibility by allowing types themselves to vary parametrically |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
|
| Higher-order functions
|
| Static versus dynamic typing
|
| Polymorphic types
|
| Algebraic types and patterns
like a context-free grammar, but labelled explicitly to indicate alternative forms chosen |
| ACM Student Chapter Lecture |
Functional programming: an alternative paradigm | Declarative versus imperative style
|
| Pure versus "impure" functional semantics
|
| Algebraic versus prefix
|
| Higher-order functions
|
| Static versus dynamic typing
|
| Polymorphic types
|
| Algebraic types and patterns
|
| Monads and continuations for effects and control
using some subtle semantic constructs, we can recover at least the illusion of side-effects |