Home » Teaching topics » Functional Programming

# Category Archives: Functional Programming

### Subscribe to Blog via Email

Join 7 other subscribers.

## Function composition

Good functional programmers will construct functions that are modularised and pure so that they don’t produce any side effects. This means that functions will be limited in scope as to what they can (or perhaps shouldn’t) affect. They should handle small, simple tasks that, when called, produce individual results. (more…)

## Review 1: Lists and functions

When teaching programming theory it is best to apply some of the concepts as practical examples. Often teachers neglect one area or the other but pupils need to see how both elements relate. Teaching content from any of the previous posts should be punctuated with appropriate examples but it is now a good point to try and draw lists and functions together into more concrete examples that apply the skills learnt so that we can solve problems.

## Partial function application

We saw previously that functions in Haskell take single arguments. There are ways around passing multiple arguments into a function but this is restrictive as we have to ensure we always call the function with the same number of arguments.

## Applying functions

Functions are the basis of all processing carried out in functional programs. We give them arguments from the domain and they produce results from the co-domain. In the previous post we coded a function but now we will look in more detail at how they work in Haskell.

## What are functions?

It’s about time we considered the function part of Functional Programming if we are going to write any useful programs! The AQA specification outlines some theory about what functions are. Whilst this is not crucial for understanding how to program using Haskell, it helps us understand what we should be trying to achieve and, importantly, the key terms we should use:

## Lists

Lists were mentioned in a previous post but we need to look at them in more detail considering how often they will be used when creating Functional programs.

## Data types

Haskell uses static typing. This means that the data type of any assignment or expression evaluation is determined at compile time before the program is run, (some languages don’t decide this until the program is running.) This generally means that the code you produce is less prone to errors as any clashing types in expressions will be caught before the program runs. It is worth considering that functions we write and their associated parameters should also be given a specified type.

## Getting started with the basics

For anyone who is familiar to IDLE for Python, Haskell has a similar interactive shell called GHCi. On a Windows install there is a GUI version called WinGHCi which, when loaded, looks like:

## What is Functional Programming?

If you didn’t know, Computer Science A-level specifications are changing from September 2015. Computing is filtering through the Key Stages all the way to Primary school. It follows that some topics traditionally taught at University level are going to need to be pushed down as well if we are going to stretch the pupils we teach.

One topic that teachers seem cautious of is Functional Programming, (though only for those teaching the AQA specification). It doesn’t appear in the AS specification so it’s likely that most schools will only teach this in Year 13. The details in the specification stretch over 4 pages which some find daunting. I personally prefer that exam boards take this approach rather than omit details that are useful for medium-term planning.