Using functions that we've defined

A Hope program is just a a single expression containing one or more function applications composed together. It's evaluated immediately and the result and its type are printed on the screen. Here's a simple program that uses max, with its output on the line below:

     max ( 10, 20 ) + max ( 1, max ( 2,3 ) ) ;
     23 : num
The rules for evaluating the expression are the same as those of Pascal: function arguments are evaluated first, the functions are applied, and finally other operations are performed in the usual order of priority.

We can also use existing functions to define new ones. Here's the Hope version of MaxOf3:

     dec MaxOf3 : num # num # num -> num ;
     --- MaxOf3 ( x, y, z ) <= max ( x, max ( y, z ) ) ;



Roger Bailey <rb@doc.ic.ac.uk>