(* Example of polymorphism and type checking in ML from pages 240-243 of Kenneth C. Louden, Programming Languages Principles and Practice 2nd Edition Copyright (C) Brooks-Cole/ITP, 2003 *) fun max (x, y, gt) = if gt(x,y) then x else y; fun gti (x:int,y) = x > y; fun gtr (x:real,y) = x > y; fun gtp ((x,y),(z,w)) = gti (x,z); max(3,2,gti); (* returns 3 *) max(2.1,3.2,gtr); (* returns 3.2 *) max((2,"hello"),(1,"hi"),gtp); (* returns (2,"hello") *) fun ident x = x; fun makepair (x,y) = (ident x,ident y); makepair(2,3.2); (* ok -- ident has two different types, one for each call *) fun makepair2 (x,y,f) = (f x, f y); makepair2(2,3.2,ident); (* type error -- ident cannot have general type *)