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…)
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.
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:
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.
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.