[Haskell-beginners] process with mutable state in haskell

Jason Dusek jason.dusek at gmail.com
Sun Dec 23 18:45:14 CET 2012


2012/12/23 Alexander _ <anotherworldofworld at gmail.com>:
> Can i run process with some mutable state and communicate with
> it in haskell? Something like gen_server in erlang.

There are many ways implement this kind of communication in
Haskell, among them. There has been some work done on an
Erlang-like library, as well; but it's name escapes me at
present. Common tools for shared state management in Haskell
include: STM, Chan, MVar and IORef.

All these mechanisms allow one Haskell thread to talk to another
Haskell thread. (In Haskell programming, we tend to use the term
"process" only to refer to an operating system process.)

To talk to a thread on another computer -- which necessarily
crosses system boundaries -- is not so easy in Haskell. It is,
at least, not as transparent as it is in Erlang. (Of course,
there are always file handles...)

Here is a link to a relatively small program I recently wrote,
using STM to buffer input and flush it at a fixed frame rate:

  https://github.com/solidsnack/shuttercat/blob/master/shuttercat.hs

It makes use of just TChan and TVar from the STM package.

--
Jason Dusek
pgp // solidsnack // C1EBC57DC55144F35460C8DF1FD4C6C1FED18A2B



More information about the Beginners mailing list