[MLton-user] Improved Exn.withEscape
    Stephen Weeks 
    sweeks at sweeks.com
       
    Tue Aug 29 09:47:53 PDT 2006
    
    
  
> Well, I have withLabel and exitTo bound at the top-level for
> convenience (although they are not used frequently).  It is quite
> rare to need multiple exitTo invocations in a single function so it
> usually doesn't make sense to name it like above.
Yeah, that one use is the common case is what lead me to
  val withEscape: (('a -> 'b) -> 'a) -> 'a
The point is that in the common case it requires the least verbiage
  withEscape (fn e => ... e x ...)
And, it can still be re-polymorphised in exactly the same way as the
void withEscape, should one need multiple uses.
> It is well known that the H-M type system infers polymorphic types
> for non-terminating terms.  When I look at the type of exitTo
>
>       val exitTo : 'a t -> 'a -> 'b
> 
> It is quite clear to me that it can't return normally.
Agreed.
> The withLabel+exitTo approach also parallels the way callcc is often
> typed in ML (http://mlton.org/MLtonCont).
Good point.  It just feels like overkill in this case since there
aren't any other operations on labels other than throw.  The overhead
does go down if one puts withLabel+exitTo at the top level, but it's
still two functions instead of one, and I'm not sure it's worth going
to the toplevel in either case (whereas for "dead" or "undefined" it
pretty clearly is).
> I also worry about the efficiency of the implementation.  The
> withLabel + exitTo approach avoids having to build a closure and is
> likely to yield slightly better generated code (on any compiler).
Wrong, at least in the case of MLton.  There will be no closure.  In
fact, in many cases, MLton will even avoid allocating the exception.
    
    
More information about the MLton-user
mailing list