Exercise 4 - FilterExercisesExercise 2 - An accumulatorExercise 3 - Operations over functionsDocumentation and user's manualTable of contentsOCaml programs

Exercise 3 - Operations over functions

 1 
  First consider mathematics.

Let f and g be functions that map real numbers to real numbers. Then f+g denotes the function that maps x to f(x)+g(x) and is called the sum of f and g. Similarly f g denotes the function that maps x to f(x) g(x) and is called the product of f and g.

Now consider programming.

Use  float  values to represent real numbers. Write functional values that compute the sum and the product of functions that map real numbers to real numbers. Name them  sum  and  product .

Is  (float -> float) * (float -> float) -> (float -> float)  the type of  sum  and of  product ?

Write applications of  sum  and of  product .

Write applications of results of applications of each of them.

 2 
  Using  accumul_right  and  product  write the functional value that computes the product of all the elements in a list of function mapping real numbers to real numbers.

Write applications of this functional value.

Write applications of results of such applications.

 3 
  Now climb up in abstraction.

Look at the definitions of  sum  and  product . Clearly their structures are similar.

Identify what is identical in them and what is not.

Then transform what is identical into a functional value that can be applied to obtain the value of  sum  or that of  product . Name  phi  this functional value.

Write the type of  phi .

 4 
  Write applications of  phi  whose results are the values of  sum  and of  product .

Write another application of  phi , then an application of the result of this application and finally an application of its result.


Latest update : October 5, 2006
This document was translated from LaTeX by Hyperlatex 2.5, which is not the latest version of Hyperlatex.

Exercise 4 - FilterExercisesExercise 2 - An accumulatorExercise 3 - Operations over functionsDocumentation and user's manualTable of contentsOCaml programs