Introduction to Functional Programming – Lecture content TDA555 / DIT440, LP1 2016 Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ Fire | Forum | TimeEdit | YouTube | Links
 Introduction to Functional Programming – Lecture content TDA555 / DIT440, LP1 2016 Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ Fire | Forum | 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.

### 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

Material:

Exercises:

### Data Types

Purpose:

• Modelling problems using data types with components
• Using recursive data types to model things of varying size
• Using recursive functions to manipulate recursive data types
• Introduction to testing with properties
• Prepare for lab 2

Content:

• Defining non-recursive and 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:

### Recursive Data Types and Lists

Purpose:

• Explain data types from the previous lecture in detail
• 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
• Prepare for lab 4

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

Purpose:

• Show how to parse (read) expressions from strings
• Prepare for lab 4
• Show another example of a recursive tree data type
• Demonstrate the use of higher-order functions

Content:

• Parsing
• Case expressions
• Testing a parser
• 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:

(Given in 2015)

Purpose:

• Show how to write graphical user interfaces (GUIs) in Haskell
• Show the design philosophy of separating program logic from interaction
• Prepare for lab 4

Content:

• The Haste compiler
• Building web pages in Haskell
• Interactive web pages
• Graphics and animations

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: