- Functions as first-class values.
- Algebraic and abstract data types.
- Polymorphism and classes.
- Testing functional programs.
- Lazy evaluations and infinite objects.
- Monads.

- Write small to medium-sized functional programs for a variety of applications.
- Exploit a variety of programming techniques typical in functional
programming, such as:
- Use of recursion,
- Modelling with recursive datatypes,
- Abstraction and reuse with the help of higher order functions and monads.

- Appreciate the strengths and possible weaknesses of the functional programming paradigm.

- This is a key aspect of functional programming.
- Higher order functions
- Powerful way to build modular and reusable code.
- Especially when combined with polymorphism.

- Powerful way to build modular and reusable code.
- Using functions to represent data

**data****Set**`a``empty`**::****Set**`a``singleton`**::**`a`**->****Set**`a``insert`**::**`a`**->****Set**`a`**->****Set**`a``union`,`intersection`,`difference`**::****Set**`a`**->****Set**`a`**->****Set**`a``complement`**::****Set**`a`**->****Set**`a``member`**::**`a`**->****Set**`a`**->****Bool**`toList`**::****Set**`a`**->**[`a`]- Probably need some constraints, or
**Eq**`a`, depending on implementation.**Ord**`a`

- Lists
**data****Set**`a`**=****Set**[`a`]

- Binary search trees
**data****Set**`a`**=****Empty****|****Node**`a`(**Set**`a`) (**Set**`a`)

- Functions
**data****Set**`a`**=****Set**(`a`**->****Bool**)

- Which is easier?

**data****Set**`a`**=****Set**[`a`] -- Invariant: no duplicates`empty`**=****Set**[]`singleton``x`**=****Set**[`x`]`insert``x`(**Set**`xs`)**|**`x```elem```xs`**=****Set**`xs`**|**`otherwise`**=****Set**(`x`**:**`xs`)`member``x`(**Set**`xs`)**=**`x```elem```xs`- Fairly easy.
- Variant: keep the lists ordered for efficiency.

**data****Set**`a`**=****Empty****|****Node**`a`(**Set**`a`) (**Set**`a`) -- Invariant: smaller elements to the left, -- bigger to the right`empty`**=****Empty**`singleton``x`**=****Node**`x`**Empty****Empty**`insert``x`**Empty****=**`singleton``x``insert``x`(**Node**`y``l``r`)**|**`x``==``y`**=****Node**`y``l``r`**|**`x``<``y`**=****Node**`y`(`insert``x``l`)`r`**|**`x``>``y`**=****Node**`y``l`(`insert``x``y`)`member``x`**Empty****=****False**`member``x`(**Node**`y``l``r`)**=**`x``==``y``||``member``x`(**if**`x``<``y`**then**`l`**else**`r`)- More complicated.
- Even more complicated if we want to keep the trees balanced. (Data.Set)

**data****Set**`a`**=****Set**(`a`**->****Bool**)`empty`**=****Set**(`const`**False**)`singleton``x`**=****Set**(`==``x`)`insert``x``s`**=**`union`(`singleton``x`)`s``member``x`(**Set**`f`)**=**`f``x``union`(**Set**`f`) (**Set**`g`)**=****Set**(**\**`x`**->**`f``x``||``g``x`)`intersection`(**Set**`f`) (**Set**`g`)**=****Set**(**\**`x`**->**`f``x``&&``g``x`)`complement`(**Set**`f`)**=****Set**(`not``.``f`)`difference``s1``s2`**=**`intersection``s1`(`complement``s2`)- It's the easiest of the tree! All operations are one-liners!
- Can implement , but not
`complement`, unlike the others.`toList`

**type****Region****=****Point****->****Bool****type****Point****=**(**Double**,**Double**)- This makes all operations on regions easy to define
- Basic shapes: circles, rectangles, etc
- Geometric transformations, e.g. moving, scaling & rotating regions
- Unions, intersections, complements
- Membership tests

- QuickCheck
- Using to examine test data distribution.
`collect` - Testing functions with preconditions (e.g. ).
`insert`

- Using
- Monads
- Informative error messages from the monadic evaluator

- Laziness
- The fringe eguality example.
- Lazy IO.

- GHC is implemented in Haskell.
- Hackage: lots of free Haskell libraries and applications.
- Investment banking: financial modelling, quantitative analysis.
- Facebook: HaXL, spam filtering.
- Keera Studios: game development, Android.
- More: Haskell in Industry

- These slides: formatting and syntax high-lighting.
- Web Fudgets: Othello.
- Programatica: Haskell compiler front-end (2001-2006)
- House: a prototype operating system in Haskell (2004-2006)
- Hardware emulation (6502 8-bit processor, used in C-64)
- An e-commerce system in Haskell (2006-2009)
- A web browser in Haskell (mid 1990s)
- Alfa: GUI for the proof assisant Agda (mid 1990s)
- Fudgets: GUI library in Haskell (early 1990s)

- Good luck with your projects!
- See you next week!