Introduction to Functional Programming – Lecture content TDA555 / DIT440, LP1 2018 Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ Fire | WaitList | Slack | TimeEdit | YouTube | Links
 Introduction to Functional Programming – Lecture content TDA555 / DIT440, LP1 2018 Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ Fire | WaitList | Slack | TimeEdit | YouTube | Links

This page describes the purpose and content of each lecture. This gives you a way to check that you have understood the expected concepts and it can also be used as an index to find out where in the material certain concepts are covered. Links to the most recent videos of actual lectures are given on the full schedule. This page contains links to other materials.

### Cases and Recursion

Purpose:

• Present general course information
• Prepare for lab 1

Content:

• Basic function definitions
• Evaluation by substituting variables in expressions
• Guards, if-then-else
• Recursion
• Types:
• `Integer`, `Bool`
• Functions with many arguments (curried functions)
• Quick introduction to lists and strings

Other Material:

Exercises:

### Data Types

Small change in 2017: we will not cover recursive data types until later in the course.

Purpose:

• Introduction to Lists
• Modelling problems using data types with components
• Using recursive data types to model things of varying size (postponed until later in 2017)
• (Not covered in 2017 until later) Using recursive functions to manipulate recursive data types l things of varying size
• Introduction to testing with properties
• Prepare for lab 2

Content:

• Defining non-recursive data types
• Data constructors
• Record syntax
• Automatic deriving of type class instances (`Eq` and `Show`)
• Wildcards `_` in function definitions
• QuickCheck:
• Properties
• Implication `==>`
• The `Arbitrary` class
• etc.

Material:

### Lists

Purpose:

• Explain polymorphic types and types with class constraints
• Prepare for lab 2 and lab 3

Content:

• Data type definitions
• Data constructors
• Defining functions by pattern matching
• Programming with lists

Material:

Exercises:

### More Lists

Purpose:

• Demonstrate programming with lists
• Explain list comprehension
• Demonstrate using QuickCheck
• Prepare for lab 3

Material:

Exercises:

### IO Instructions

Purpose:

• Explain how pure functional programs can interact with their environment
• Focus on how to use IO without explaining the underlying details

Content:

• Standard functions for input/output
• The `IO` type (“instructions”)
• Composing instructions
• `do` notation
• Conditional and recursive instructions

Material:

• The slides
• A good blog post that explains how to use IO without understanding the underlying theory.
• LYAH: Chapter 9, sections 1-4 (“instructions” are called “actions” in the book)
• Optional: Video recordings of a similar lecture: part 1, part 2

### Test Data Generation

Purpose:

• Show how to generate QuickCheck test data for new data types (a bit outdated)
• Show how to generate test data tailored to specific problems
• Show an example of an “instruction type” different from `IO`

Content:

• The `Gen` type for test data generators
• Making complicated generators from basic ones
• using combining functions
• using `do` notation
• The `Arbitrary` class
• Generate data types with invariants
• How to affect the distribution of test data

Material:

### Higher-Order Functions

Purpose:

• Teach the general concept of higher-order functions
• Show how higher-order functions can be used to capture reusable programming patterns

Content:

• Higher-order functions: functions that take functions as arguments or return functions
• Types of higher-order functions
• Higher-order functions in Haskell’s libraries (`map`, `filter`, `fold`, etc.)
• λ-expressions
• Operator sections
• Function composition `(.)`
• Partial applications
• “Curried” functions
• Solving problems using existing higher-order functions
• How list comprehensions are translated

Material:

### Recursive Data Types

Purpose:

• Show how to use recursive data types to model tree-shaped data
• Show how to model and work with simple expression languages

Content:

• Representing expressions
• Pretty printing (showing) expressions as strings
• Making a custom instance of the `Show` class
• Generating random expressions
• Evaluating and manipulating expressions

Material:

### More Recursive Data Types

This lecture will change in 2018 as we will not cover parsing.

Tentative new plan: extended example (the Zoo Game) ; rose trees.

Purpose (2017):

• Trees with many branches (a “bush” or a “rose tree”)
• Extended example

Content:

• Rose Trees
• Game for guessing animals using yes/no questions

Material:

### Data Structures

Purpose:

• Show examples of functional data structures
• Show basic reasoning about efficiency of data structures
• Show how to move from an inefficient specification to an efficient implementation without introducing bugs
• Show the concept of abstract data types

Content:

• Queue data structure
• Table data structure
• Using QuickCheck to verify efficient implementations

Material:

### Laziness and Parallelism

(Not given in 2016)

Purpose:

• Explain lazy evaluation and its benefits
• Raise awareness of the increasing use of parallel hardware and the need to run computations in parallel
• Show how pure functional programs are suitable for parallelization
• (Hopfully live demo on a multi-core machine)

Material: