Next: Global Function Type Inference
Up: Type Inference
Previous: Variable Type Inference
  Contents
  Index
Local Function Type Inference
type inference
The types of arguments to local functions are inferred in the same was
as any other local variable; the type is the union of the argument
types across all the calls to the function, intersected with the
declared type. If there are any assignments to the argument
variables, the type of the assigned value is unioned in as well.
The result type of a local function is computed in a special way that
takes tail recursion ( see section tail-recursion) into consideration.
The result type is the union of all possible return values that aren't
tail-recursive calls. For example, Python will infer that the
result type of this function is integer:
(defun ! (n res)
(declare (integer n res))
(if (zerop n)
res
(! (1- n) (* n res))))
Although this is a rather obvious result, it becomes somewhat less
trivial in the presence of mutual tail recursion of multiple
functions. Local function result type inference interacts with the
mechanisms for ensuring proper tail recursion mentioned in section
5.6.5.
Next: Global Function Type Inference
Up: Type Inference
Previous: Variable Type Inference
  Contents
  Index
Peter Van Eynde
2001-03-08