Cambridge University Press 1.1 Time Clock User Manual


 
46 CHAPTER 4. EFFECTIVE CAML
#let I x = x;;
I : ’a -> ’a = <fun>
#I o I;;
it : ’_a -> ’_a = <fun>
#let I2 = I o I in fun x -> I2 x;;
it : ’_a -> ’_a = <fun>
#fun x -> (I o I) x;;
it : ’a -> ’a = <fun>
Other techniques for polymorphic references often rely on encoding in the types
the fact that an expression may involve references. This seems natural, but it can
lead to the types of functions becoming cluttered with this special information. It
is unattractive that the particular implementation of the function, e.g. imperative
or functional, should be reflected in its type.
Wright’s solution, on the other hand, uses just the basic syntax of the expression
being let-bound, insisting that it is a so-called value before generalizing the type.
What is really wanted is knowledge of whether the expression may cause side-effects
when evaluated. However since this is undecidable in general, the simple syntactic
criterion of its being or not being a value is used. Roughly speaking, an expression
is a value if it admits no further evaluation according to the CAML rules this
is why an expression can often be made into a value by performing a reverse eta
conversion. Unfortunately this works against the techniques for forcing evaluation.
Further reading
Hints and tips for practical programming can be found in many functional program-
ming books, e.g. Paulson (1991). Methods used by language implementations to
perform garbage collection are discussed in depth by Jones and Lins (1996).