Intro to FP
History
- 1930: Alonzo Church developed Lambda Calculus (any program can be created from compositions of pure functions)
- 1937: Turing and lambda calculus are equivalent
- 1958: John McCarthy created Lisp (added GC, closures, etc.)
- 1987: FPCA created Haskell (Curry), named after Haskell Curry
Principles of FP
- Every function must return value
- Every function must take value
- Every function must be pure (no side effects, always returns the same value for a given input)
- Functions are first-class citizens
- All variables are immutable
Pure Function (referentially transparent function):
- Given a specific input x, will return same output y
- Computes output exclusively on input parameters without relying on or modifying external data
Make code easier, debug, test, parallelism, compiler optimization, formally analyze and prove
Note that in FP, order of exec importance is low. How?
No side effects, everything is lazy.
Haskell Introduction