[Haskell-cafe] What's a thread doing / Erlang-style processes / Message passing

Bulat Ziganshin bulatz at HotPOP.com
Tue Dec 6 11:07:16 EST 2005

Hello Joel,

Tuesday, December 06, 2005, 5:12:55 PM, you wrote:

>> using "Dynamic" have meaning only if you don't know at compile time
>> what
>> messsages can be sent. is that really the case?

JR> That is correct. I deliver a "scripting library" and users can create
JR> messages of their own.

creators of Data.List library also don't know about all your types,
but nevertheless you are use all theirs functions ;)

if set of messages is defined at compile time, then it's just:

data Event a = Quit
             | ....
             | User a

user of your library defines additional set of messages with

data UserEvent = Beer Int | Cola | ...

and use smthg like

do chan <- newChan
   sendChan chan (User $ Beer 5)
   sendChan chan Quit

it seems like magic but Haskell will guess what `chan` have type
"Chan (Event UserEvent)" here :)

>> imho, you are think in Erlang style, which is ultimately dynamic and
>> run-time oriented.

JR> I think in the style most suitable to my task at hand. I have a variable
JR> number of poker clients that talk to the server. These all run  
JR> concurrently
JR> so I'm starting threads for them. They can send/receive messages, so  
JR> I added
JR> mailboxes to the threads, etc. Is there anything wrong with this  
JR> approach?

hm, may be that you are mixing interfaces and implementation details.
for example, poker client in my taste must be a record which supports all
operations on this client via its fields, which is just an actions
which accepts/returns some values

in general, your questions contain too few details about your
problems and too much details about solutions you are assume

Best regards,
 Bulat                            mailto:bulatz at HotPOP.com

More information about the Haskell-Cafe mailing list