[Haskell-beginners] Interrupting a thread

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Dec 31 06:26:28 EST 2009


On Thu, Dec 31, 2009 at 9:21 AM, Floptical Logic
<flopticalogic at gmail.com> wrote:
>> You'll want something like this:
>>
>> myFork :: StateT MyState IO () -> MyState -> StateT MyState IO ThreadId
>> myFork action initialState = liftIO (forkIO (evalStateT action
>> initialState))
>
> That's not quite what I'm looking for.  I don't want to create a new
> thread in which to run the monad but rather to be able to create
> threads from inside the monad (as a result of running the monad).

And that's what this code does. Do you want it to automatically use
the state of the monad ?

> myFork :: StateT MyState IO () -> MyState -> StateT MyState IO ThreadId
> myFork action = liftIO . forkIO . evalStateT action =<< get

keep in mind that nothing the thread will do will affect the state of
the main thread.

-- 
Jedaï


More information about the Beginners mailing list