In this lecture we do a quick recap of Haskell and talk about things like referential transparency, laziness, type classes, and we take a brief look at a first simple example of a domain specific embedded language: Signal. The code from the lectures is slowly migrating from this homepage to a new AFP course page on github. You are very welcome to help with the migration.

- The World: Ch. 1-6, Ch. 8-10 (mostly repetition of intro. FP). Note that it is ~200 pages, so start reading now if you need an update!
- Optional: Applicative Functors are introduced in RWH10, used more later in RWH16
- Optional: The Craft: Chapter 12 on overloading, Ch. 16 on abstract types, Ch. 17 on laziness
- Optional: The School: Chapter 12 on type classes, Ch. 14 on streams, Section 18.1 on higher-order types

- Why Functional Programming Matters by John Hughes.

In this lecture we develop domain specific embedded languages for describing signals and shapes. We talk about the distinction between a deep and a shallow embedding, about compositionality and abstraction.

- The code above: read it or try to reproduce it.
- The World: Not quite the same terminology but, Ch. 5 has an EDSL for pretty printing, Ch. 9 one for file searching and Ch. 13 one for arithmetic expressions.
- The School: Chapter 2 (the inspiration for this lecture)

- Extend the library to allow coloured shapes.
- Improve rendering resolution by sampling two pixels per character,
using "
`o`" for the bottom pixel, "`°`" (degree sign) for the top pixel, and "`8`" for when both pixels are set.

This lecture introduces functors and monads by looking at how to design a simple library for input/output.

- Implement more Functors and Monads.
- Turn the snake game into a two player game.
- (
*More ambitious*) Change the Program library to allow file I/O.

- Chapter 14 in RWH
- Optional: Chapter 15 in RWH
- Monad tutorials

- How to Declare an Imperative by Phil Wadler (on the IO monad). This lecture is mainly about pages 1-13.
- Monads for functional programming by Phil Wadler. (Can be seen as a preparation for lecture 5 as well.)

In this lecture we look at another application of monads, namely parsing. We also see how to refine the implementation of a library. Starting from a naive translation from syntax to semantics, we derive intermediate representations for an efficient implementation. The focus here is on learning outcome "Spec: use specifictaion based development techniques".

- Prove (some of) the laws stated in the paper (and in Parser0).

- Chapter 16 in RWH, until p. 390 or so; to get a feel for what parser combinators are.
- Parallel Parsing Processes by Koen Claessen.

- Monadic Parser Combinators by Graham Hutton and Erik Meijer.
- The Design of a Pretty-printing Library by John Hughes.

We learn how to build complicated monads from simple building blocks.

- Implement the
`Program`type from lecture 3 using monad transformers.

- Chapter 18 in Real World Haskell on Monad Transformers.

- Monad Transformers and Modular Interpreters by Sheng Liang, Paul Hudak, and Mark Jones.

This lecture was spent working through the StateT and ErrorT monad transformers in the interpreter example before the break and transforming looking at the Monad and Parser laws after the break. The code and the recommended reading material can be found above in lecture 5.

In this lecture / excercise session we will work through old AFP exam questions in groups to identify important topics and practice collaborative problem solving and discussion. This is in response to student comments from last year wanting more practice of the kind of problems typically included in the written exams.

We look at program verification: proving, specifying and testing correctness of programs.

- Chapter 11 in Real World Haskell on Testing and quality assurance.
- Chapter 2 in The Fun.

- QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs, by Koen Claessen and John Hughes.

Title: Designing EDSLs by combining Deep and Shallow Embeddings

I will present a design pattern for embedded DSLs (EDSLs) where a combination of deep and shallow embeddings is used in order to get most advantages from both approaches. This approach has been successfully used in Feldspar which is an EDSL for high-performance numeric computations. I will also introduce Feldspar and discuss some details of its implementation.

- Combining Deep and Shallow Embedding for EDSL, published in the International Symposium on Trends in Functional Programming (TFP 2012).

In this lecture we continue the work on QuickCheck, mainly looking at
how to generate and shrink test data. We base the work on a compiler example and show how the program coverage
tool `hpc` can be used to see what parts of a program has been tested.

- The hpc documentation on the Haskell Wiki.

We look at GADTs in more detail using an embedded DSL with two types to illustrate the different options.

- GADTs on the Haskell Wiki.

In dependently typed languages such as Agda one can both write programs and proofs about the programs. Agda can be seen as a "next generation Haskell".

- L12 source code on github
- Ulf Norell's tutorial Dependently Typed Programming in Agda.
- The Agda wiki.

Type families and associated types in Haskell

- Type families on the Haskell Wiki.

- Slides by Simon Peyton-Jones: Fun with Type Functions.
- L13 source code on github

- Fun with Type Functions by Oleg Kiselyov, Simon Peyton Jones and Chung-chieh Shan.

One of the most important advantages of functional programming languages is that they allow us to construct programs from specifications by *calculation*. The expressivity of functional programming enables the formulation of specifications as (usually very inefficient) programs, which can then be optimized by equational reasoning using algebraic identities, in a process reminiscent of high-school mathematics. In this lecture, we will introduce a number of such algebraic identities, and use them in the presentation of a "canonical" example of program calculation: computing a linear-time solution to the maximum segment sum problem.

Micro-bio: Cezar Ionescu is currently a PostDoc on "Increasingly Correct Scientific Computing" in the FP group at Chalmers. Before that he worked for several years at the Potsdam Institute for Climate Impact Research where he applied AFP in the form of Haskell, C++, Agda and Idris to Computational Vulnarability Assessment, Scientific Computing and Economic Models.

Reading:

- Chapter 6 of "Thinking Functionally with Haskell", Richard Bird, Cambridge University Press, 2014
- Chapter 4 of "Introduction to Functional Programming using Haskell second edition", Richard Bird, Prentice Hall, 1998
- "Algebraic Identities for Program Calculation", Richard Bird, The Computer Journal, Vol. 32, No. 2, 1989, pp 122-126

Second instance of the excercise session with exam questions.

In this lecture we briefly look back at the learning outcomes and how they relate to the different parts of the course and what parts of the RWH book are covered. Then we go through a few examples chosen by popular vote by the participants. (2015: RWmonad, Newtype deriving, Continuation monad.)

- L16 source code on github
- An Arrows tutorial.