Informative Jottings Pieces of Useful Information

Solution to "Integer Identifiers" problem on Learn OCaml

Here’s the problem:

Suppose that a variable x exists and is an integer.

Define a variable x_power_8 that uses three multiplications to calculate x to the power of 8. The only function you are allowed to call is the (*) operator.

Hint: use auxiliary variables.

Solve this exercise using a nested sequence of auxiliary variable definitions. Here is a definition of x_power_8 which Learn OCaml recognizes as correct:

This can be written more simply if we use the Jane Street stdlib, Base. Assuming you have the library available, entering the following lines of code into utop will work: