Lecture

**Lecture:** Thur, 10:15-11:45, F119, Sand 6/7

**Tutorial:** Tue, 14:15-15:45, F119, Sand 6/7

**Exam:** Thur 17.7.2014, 16:00-18:00 (N6, Morgenstelle)

Numbers are values. Strings are values. Booleans are values. In "functional programming", *functions* are "simply" values as well. This view on programming leads to an elegant and expressive programming paradigm which we will investigate in this course. During the course, we will use the programming language Haskell. The majority of the concepts we will consider applies in other (functional) languages as well.

Participants are not expected to be fluent in Haskell from the beginning. We will spend the first three weeks of the semester on a *Haskell Ramp-Up*. Things will progress rather fast, though. The majority of the semester will be used for the *good stuff*: intermediate and advanced topics, of which there are plenty.

Weekly exercise sheets are provided on the teaching platform **Ilias**. Please register at the following link for the exercises: Functional Programming in Ilias. The first exercise sheet will be handed out on Monday, 14.04.2014 at 14:00.

The following introductory books on Haskell are available online:

- Lipovača: "Learn You a Haskell for Great Good", No Starch Press 2011. Available online at learnyouahaskell.com/chapters
- O'Sullivan, Stewart, Goerzen: “Real World Haskell”, O’Reilly 2010. Available online at book.realworldhaskell.org

We will refer to additional material for the individual topics during the semester.

Additional material (code, data)

Nr | File | Download |
---|---|---|

1 | ice-cream.hs The - Compile with Haskell compiler ghc via
`ghc --make ice-cream.hs` , execute with`./ice-cream` . - Load into REPL ghci via
`ghci ice-cream.hs` , then evaluate function`main` .
| |

2 | isPrime.hs | |

3 | lazy-factors.hs | |

4 | infix-op.hs Declares a user-defined infix operator | |

5 | factorial.hs Conditional expression vs. guards | |

6 | power.hs Function definition using guards and local | |

7 | tally.hs Conditional expression vs. guards vs. pattern matching | |

8 | take.hs Compute a finite prefix of an (infinite) list — demonstrates pattern matching | |

9 | mergesort.hs Mergesort (with a user-defined ordering relation) — demonstrates pattern matching, local | |

10 | weekday.hs Demonstrates algebraic sum types (enumerations) | |

11 | sequence.hs Demonstrates algebraic product types | |

12 | cons.hs Demonstrates algebraic sum-of-product types (cons lists) | |

13 | eval-compile-run.hs Use algebraic data types to represent, evaluate, compile, and execute simple arithmetic expressions | |

14 | rock-paper-scissor-inst.hs Manually implement | |

15 | rock-paper-scissor-inst-deriving.hs Use | |

16 | library-exposed.hs Implements integer sets as unordered lists, implementation fully exposed | |

17 | SetLanguageShallowCard.hs Shallow embedding of a DSL for integer sets (uses a Haskell module to hide the implementation in terms of characteristic functions) | |

18 | set-language-shallow.hs Imports and exercises the shallow integer set DSL embedding in | |

19 | SetLanguageDeepCard.hs Deep embedding of a DSL for integer sets (observers | |

20 | set-language-deep.hs Imports and exercises the deeply embedded integer set DSL in module | |

21 | ExprDeepNum.hs Deep embedding of a super-simple expression language (with | |

22 | expr-deep-num.hs Imports | |

23 | ExprDeepGADTTyped.hs Using GADTs to construct a type-safe deeply embedded DSL over integers and Booleans. | |

24 | expr-language-typed.hs Imports | |

25 | ExprShallowPrint.hs Shallow embedding of a DSL for expressions with | |

26 | expr-language-shallow-print.hs Imports | |

27 | PatternMatching.hs A shallowly embedded DSL for string pattern matching. Based on Philip Wadler's seminal 1985 paper | |

28 | simple-patterns.hs Imports | |

29 | pattern-matching.hs Imports | |

30 | sequence-Maybe.hs Sequencing partial functions | |

31 | sequence-Either.hs Sequencing exception-generating functions | |

32 | sequence-ST.hs Sequencing stateful functions | |

33 | monadic-Maybe.hs Monadic sequencing of partial functions | |

34 | monadic-Either.hs Monadic sequencing of exception-generating functions | |

35 | monadic-NonDet.hs Monadic sequencing of non-deterministic functions (i.e., relations) | |

36 | monadic-ST.hs Monadic sequencing of stateful functions | |

37 | monadic-do-NonDet.hs Reformulating | |

38 | IOaction.hs Demonstrates how the construction of IO actions is decoupled from their effectful execution (free monad | |

39 | Perhaps.hs Data type | |

40 | hiking.hs Super-simple demonstration of the | |

41 | Probability.hs Monad | |

42 | dice.hs Throwing one die/two dice and the resulting probability distribution (uses | |

43 | parFibPie.hs Using primitives Compile via Spark profile can be inspected via | |

44 | parFibPies-force.hs Using | |

45 | DeepSeq.hs Making a user-defined algebraic data type an instance of class | |

46 | ParIndices.hs A parallel variant of | |

47 | indices.hs Wrapper that measures execution time of Execute via | |

48 | ParFoldMap.hs Parallel monoid reduction ( | |

49 | Wookie.txt Illustration: Splitting an input text into its whitespace-separated words. A formulation of the problem in terms of | |

50 | WordState.hs A | |

51 | allWords.hs Uses parallel monoid reduction (over monoid ⚠ Replace Execute via |