Objectives

  • Gain an understanding of Higher Order and Anoynmous Functions
  • Understand useful higher order functions such as map and fold
  • Work with lists and write simple functions to manipulate them

Introduction

Higher order functions are quite simply functions which accept other functions as parameters. While they exist and are used in other languages (see Callback Functions), functional languages are where they really shine. Map (which applies a function to all elements of a list) and Fold (which uses a function to recursively colapse a list into a single element) are two essential higher order functions which have found their way into many programmers toolkits.

Anonymous functions (Also called lambdas) on the other hand give us a convient syntax for defining in line functions without needing to explicitly name them. Combined with higher order functions these give us powerfull new ways to manipulate data.

Learn You A Haskell

Work your way through chapter six and seven of Learn You A Haskell.

Functional Data Manipulation

This is a spread sheet containing Bicycle Count and Locations data from the City of Toronto's open data initative. Also this is a Haskell file containing the data from the "Summary (Per 15-min)" tab in a convient list. Note the time field has been split into Hours and Minutes in the tuple in the list, resulting in eleven fields from the original ten.

Extend the Haskell Script with functions for calculating following:

  • Total number of riders wearing a helmet
  • Average cyclists without a helmet in a fifteen minute period (as a double)
  • Average bikes on the sidewalk per hour (as a double)
  • Time you were most likely to see someone on the sidewalk

Make sure your script has a .hs extension and put it in your CPS506 Fossil repository.