Simple Functions

Functions are the way we can define our own operators. To do this we must make up a name for our function, give its type and then define what it does. For example:
 
f:num -> num;
f(n) <= n*(n+1);
This defines a function called f of type num -> num This means it takes a number and returns a number. If we give our function f the value n it will give us back n*(n+1)

Try inputting

 
f(3);

Hope replies:

 
>> 12 :num

Because f(3) $\rightarrow$ 3*(3+1)$\rightarrow$ 3*4 $\rightarrow$ 12.



Subsections

s.danicic@gold.ac.uk
Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2010-12-29