[MLton] Universal type wiki page wrong?
Stephen Weeks
MLton@mlton.org
Wed, 26 Jan 2005 12:43:50 -0800
> The page http://mlton.org/UniversalType seems to suggest that the following
> UNIVERSAL_TYPE implementation would be correct, just leaky:
>
> structure U2:> UNIVERSAL_TYPE =
> struct
> type t = unit -> unit
> fun embed () =
> let
> val r = ref NONE
> fun inject a () = r := SOME a
> fun project f = (f (); !r)
> in (inject, project) end
> end
>
> I think this is wrong
You're right. A correct, but leaky implementation would be
fun project f = (r := NONE; f (); !r)