Stephen Weeks MLton@mlton.org
Wed, 18 Aug 2004 09:22:33 -0700

> I'd like to propose changing the MLTON_THREAD and MLTON_SIGNAL interfaces
> to the following:
> The point is to statically distinguish between explicitly paused threads
> and implicitly paused threads.

An excellent idea.  The only thing I might change would be to use type
'a t for explicitly paused threads and type 'a u (or whatever) for
implicitly puased threads.
> Similarly, it justifies dropping switch'.  I can't find any uses of
> switch' in our code.  Any place where you were using switch', you should
> be able to first prepend and then switch -- if you were switch'-ing to an
> implicitly paused thread with a non-trivial computation, then it probably
> isn't doing what you thought anyways.

Makes sense.

> In fact, we might go so far as to use the following interface:
> signature MLTON_THREAD =
> sig
> (* the type of threads *)
> type t
> (* the type of (user) threads that expect a value of type 'a *)
> type 'a u
> val new : (unit -> 'a) -> 'a u
> val prepend : 'a u * ('b -> 'a) -> 'b u
> val freeze : unit u -> t
> val switch : ('a u -> t) -> 'a
> val atomicSwitch : ('a u -> t) -> 'a
> end
> where you first prepend a thunk to deliver the value, and then freeze.

This seems even better, since it tells the truth about implicitly
paused threads, which don't recieve a value.  It might require a
utility function or two for common cases.

As above, I would consider using type 'a t for explict and type u for
implicit.  Maybe type u should be called "runnable"?  And freeze could
be called "makeRunnable" (a bit long)?  Anyway, I think there might be
a better name than freeze, which seems a misnomer to me.