[Haskell] thread-local variables

Frederik Eaton frederik at a5.repetae.net
Sat Aug 5 21:41:17 EDT 2006

Hi Robert,

I looked over your proposal.

I'm not sure if I'm in favor of introducing a new keyword. It seems

Also, note that my proposal differs in that thread local variables are
not writable, but can only be changed by calling (e.g. in my API)
'withIOParam'. This is still just as general, because an IORef can be
stored in a thread-local variable, but it makes it easier to reason
about the more common use case where TLS is used to make IO a Reader;
and it makes it easier to share modifiable state across more than one
thread. I.e. if modifiable state is stored as 'IOParam (IORef a)' then
the default is for the stored 'IORef a' to be shared across all
threads; it can only be changed "locally" for a specified action and
any sub-threads using 'withIOParam'; and if some library I use decides
to fork a thread behind the scenes, it won't change my program's

I think it is a good idea to have stdin, cwd, etc. be thread-local.

I don't understand why the 'TL' monad is necessary, but I haven't read
the proposal very carefully.



On Sat, Aug 05, 2006 at 02:18:58PM -0400, Robert Dockins wrote:
> Sorry to jump into this thread so late.  However,  I'd like to take a moment 
> to remind everyone that some time ago I put a concrete proposal for 
> thread-local variables on the table.
> http://article.gmane.org/gmane.comp.lang.haskell.cafe/11010
> I believe this proposal addresses the initialization issues that Einar has 
> been discussing.  In my proposal, thread-local variables always have some 
> defined value, and they obtain their values at well-defined points.
> The liked message also gives several use cases that I felt motivated the 
> proposal.
> --
> Rob Dockins
> Talk softly and drive a Sherman tank.
> Laugh hard, it's a long way to the bank.
>        -- TMBG
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell


More information about the Haskell mailing list