[MLton] expansive expressions yielding polymorphic values

Stephen Weeks sweeks at sweeks.com
Thu Feb 28 10:34:53 PST 2008


>  Note,  even  though  f  is  the  result  of an expansive expression (function
>  composition), the signature Z can make its type polymorphic.
>
>  Can people confirm that this really is supposed to be legal?

I think it is supposed to be legal.  What is going on is not that "f"
is polymorphic, it is that f's type (unit -> int) is at least as
general as the type specified in the signature ('a t -> int), where
the signature matching gets to assume that 'a t = unit.  A simpler
example might be

structure Z : sig
  type 'a t
  val s : 'a t
end = struct
  type 'a t = string
  val s = "foo"
end

Also note that once you have hidden the fact that "t" is monomorphic,
clients can no longer take advantage of that fact in type checking
their own expansive expressions.



More information about the MLton mailing list