PPP Exercises: Currying


Concept of currying: In TL it is possible to 'curry' functions which means that one function may return another function which uses the parameters of the first and of the second function.

Exercise:

  1. Define a function 'add' with two integer parameters. Apply currying to the parameters. What does this mean in terms of types? Then define a function 'add3' that adds 3 to one integer parameter; use the curried version of 'add'.

    Note: Currying is especially useful with polymorphic functions!

  2. Enhance the stack definition 'FunStack' and it's implementation 'listStack' of the exercise Generic abstract data types and implementations by introducing the concept of curried functions for each function ('new', 'empty', ...). Call them 'CurryStack' and 'curriedListStack'.

  3. Then, again, implement an integer stack 'intStack :IntStack', but using this curried stack definition.

Ulrike Steffens, 1994