The word "signature" means the same as "type". The signature of f here is int -> real and the signature of sum is int * int * (int -> real) -> real. Remember that the symbol * inside a signature means Cartesian product, i.e. a record type.function f(j:int): real;
begin
return a[j]*b[j];
end;function sum (lo,hi:int; f: int->real): real;
var s: real := 0;
begin
for k := lo to hi do s := s + f(k);
return s;
end;
(1) the first item in each pair is from A and the second item
is from B
(2) for each item x in A, there is a unique y
in B such that the pair <x,y> is in the mapping.
In programming, a function that satisfies this definition is called pure. Programming functions can be impure for any or all of several reasons:
One major difference between PLs is exactly what kinds of impure functions are allowed.
Note that the implementation of a function may use one or more of the
sources of impurity just mentioned, but this impurity may be encapsulated
(i.e. hidden from users of the function) and therefore the function remains
pure from a mathematical perspective.
The ML type system is quite elegant. The principal builtin primitive types are int, real, string, and bool.pindar% sml
Standard ML of New Jersey, Version 75, November 11, 1991- val two = 2;
val two = 2 : int- fun double x = 2 * x;
val double = fn : int -> int- double two;
val it = 4 : int
Deduction: 2.0 is a real, so * must be the function of type real * real -> real, so x must be a real, so d2 must be of type real -> real.- fun d2 x = 2.0*x;
val d2 = fn : real -> real