Go backward to
Universal Quantification
Go up to
Top
Go forward to
Parametric Types
Polymorphic Functions
First version of polymorphic twice:
value twice1 = all[t] fun(f:
forall
a: a
->
a)
fun(x: t) f[t](f[t](x))
twice1[Int](id)(3) is legal.
twice1[Int](succ) is illegal!
Second version of polymorphic twice:
value twice2 = all[t] fun(f: t
->
t) fun(x: t)
f(f(x))
twice2[Int](succ) is legal.
twice2[Int](id[Int])(3) is legal.
Both versions different in nature of f:
In twice1, f is a polymorphic function of type
forall
a: a
->
a.
In twice2, f is a monomorphic function of type
t
->
t
(for some instantiation of
t
)
Author:
Wolfgang Schreiner
Last Modification: May 27, 1998