Introduction to Functional Programming – Lecture content | TDA555 / DIT440, LP1 2017 |

Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ | Fire | WaitList | Group | TimeEdit | YouTube | Links |

Introduction to Functional Programming – Lecture content | TDA555 / DIT440, LP1 2017 |

Home | Schedule | Labs | Lectures | Exercises | Exam | About | FAQ | Fire | WaitList | Group | 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.

Purpose:

- Present general course information
- Help students get started using GHCi and loading program files
- Teach basic Haskell programming
- Prepare for lab 1

Content:

- Getting started using GHCi and loading program files
- Basic function definitions
- Evaluation by substituting variables in expressions
- Guards, if-then-else
- Recursion
- Types:
`Integer`

,`Bool`

- Functions with many arguments (curried functions)
- How to read overloaded types

- Quick introduction to lists and strings

Material:

- Interactive videos Enrollment key: CMDKM-50508
- Video Part 1, 2016
- Video Part 2, 2016
- The slides
- LYAH:
- Chapter 1
- Chapter 2, sections 1-3 (but you are encouraged to read the whole chapter)
- Chapter 3, section 1 (but you are encouraged to read the whole chapter)
- There may be a few unfamiliar things if you haven’t read all of chapter 2, but you can just skip those bits

- Additional reading on Wikibooks (with exercises and solutions):
- Use Hoogle to look up any unfamiliar functions
- For example, try searching for
`+`

,`max`

or`Num`

- You can also search by type:
`a -> String +base`

(I added`+base`

to remove hits from irrelevant packages.)

- For example, try searching for

Exercises:

- Exercises week 1 For week 1.
- Exercises week 2 For the exercise class on Monday of Week 2
- The above Wikibooks links have some good exercises and solutions.

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:

- The slides
- LYAH:
- Use Hoogle to look up any unfamiliar functions

Purpose:

- Introduce Haskell’s built-in lists
- 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:

- The slides
- LYAH:
- Chapter 2
- Chapter 3
- Chapter 4
- Chapter 5
- Chapter 8, sections 1-6
- Stop when you reach the
`Tree`

type in section 6

- Stop when you reach the

**Optional:**A short complimentary blog post on data types**Optional:**Video recording of a lecture on lists

Exercises:

- 99 Haskell Problems
- Problems 1-28 are about lists
- Solutions
**Recomended:**Problems 1-18 can be worked on interactively: http://www.99haskell.org/

- Video recordings of a similar lecture: part 1, part 2

Purpose:

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

Material:

- Haskell files available on the schedule
- LYAH: You might want to read Chapter 7, sections 1-3 and section 6; however, this chapter uses some higher-order functions that we haven’t talked about yet.
**Optional:**Video recording of a similar lecture by John Hughes

Exercises:

- 99 Haskell Problems
- Problems 1-28 are about lists
- Solutions
**Recomended:**Problems 1-18 can be worked on interactively: http://www.99haskell.org/

Purpose:

- Explain how pure functional programs can interact with their environment
- Basic input/output in Haskell
- Focus on how to
*use*IO without explaining the underlying details

- Focus on how to

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

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:

- The slides
- QuickCheck manual
- QuickCheck documentation
- LYAH: Chapter 8, section 7
**Optional:**Video recordings of a similar lecture: part 1, part 2

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:

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:

- The slides
- LYAH: Chapter 8, section 6
**Optional:**Video recordings of a similar lecture: part 1, part 2

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:

- The slides: parsing, zoo game
- LYAH: Chapter 4, section 5
**Optional:**Video recordings of a similar lecture: part 1, part 2

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:

- The slides
**Optional:**LYAH: Chapter 7, section 4-5

(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:

(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:

- The slides
- Wikibooks/Haskell/Laziness
- Blog post on basic parallelism (only first part)
**Optional:**Why Functional Programming Matters- Seminal paper by John Hughes (from 1984)
- Shows how laziness allows making programs more modular

**Optional:**Haskell’s Non-Strict Semantics – What Exactly does Lazy Evaluation Calculate?- More detailed explanation of laziness, with an interesting example

**Optional:**C++ is lazy and Haskell is strict- An interesting perspective on laziness