[MLton-user] SMLofNJ.Cont.isolate

Dave Herman dherman at ccs.neu.edu
Fri Apr 25 12:20:13 PDT 2008


> I think what they really mean is that if
>   val c = isolate f
> then throw c x discards all live data ....

Yes, the documentation is bad, but I think this is what they mean.

> I'm sure it is possible to implement isolate simply in terms of callcc, 
> though it may not have the desired space behavior.

Exactly.

> With the MLton.Thread structure (different from the 
> Primitive.MLton.Thread structure referenced in 
> <src>/basis-library/mlton/cont.sml), you could get the behavior of 
> 'throw (isolate f) x' with the following:

Also known as `abort', which is all I really need. :)

> fun isolate (f: 'a -> unit) : 'a cont =
>   fn x =>
>   let
>     val t = MLton.Thread.new (f o x)
>     val r = MLton.Thread.prepare (t, ())
>   in
>     MLton.Thread.switch (fn _ => r)
>   end
> 
> All untested.  And you need to call OS.Process.exit if the isolated 
> function returns normally (or exceptionally). 

Forgive my lack of familiarity with MLton threads... do you just mean this?

     let ...
     in
       MLton.Thread.switch (fn _ => r);
       OS.Process.exit ...
     end

(I'm still trying to understand the MLton.Thread library docs, sorry.)

> And I'm not 100% sure 
> that threads and continuations play nice together, but the above seems 
> fairly benign.

*gulp*

:)

thanks,
Dave



More information about the MLton-user mailing list