On Tue, 16 Jun 1998, Greg Michaelson wrote:
> Alastair wrote: 
> >> This might form a very  nice inter-process communication mechanism,
> >> which may be recognised by people who have written interrupt driven
> >> multi-process systems.

A few people are discussing using the exceptions mechanism to allow
interprocess communications.  Using exceptions this way strikes me as
difficult at best.  

Unix shell pipes provide a really nice way to do IPC e.g.

$ cat file | grep blah | wc -l

Haskell lists and laziness allow something similar but mich
more sophisticated.  The tutorial describes a client server model
that relies on laziness to allow the user to follow the communications.

> client init (resp:resps) = init : client (next resp) resps
> server      (req:reqs)   = process req : server reqs

You can use this model for interprocess commmunications if:
* you have IO sources that generate lists of world state versions
* you have IO sinks that consume Haskell lists and change world state

The system is driven by the sinks' demand for new data.  Sources may block
until they have another version of the world to deliver.

If you want a process that checks the price of a stock on a website every
hour and sends mail if it reaches some value:

> main = do 
>         ticks <- paceMaker EveryHour 
>         stockPage <- getURL "http://www.quote.com/quote?stock=YHOO"
>         mailer <- priceMail 100.0 ticks stockPage

Pacemaker is C code that adds the current time to a list at the frequency
specified.  The process blocks until it is time to output a new tick.

> paceMaker::  Frequency -> IO [ClockTime] 
> data Frequency = EveryHour | EveryMinute | EverySecond

GetURL keeps adding the current version of some page to a list. It does
not block.

> getURL:: String -> IO [URLContent] 

Mailer takes a list of mail and sends it.  It is blocked until mail is
added to the list.

> mailer:: [Mail]-> IO () 

PriceMail is a list comprehension on clock ticks and contents.
> priceMail::Float -> [ClockTime] -> [URLContent] -> [Mail]
> priceMail price ticks contents = 
>  [Mail "[EMAIL PROTECTED]" (stockName content)++'=':(show (stockPrice content))|
>       t<-ticks, content<-contents, (stockPrice content)>price ]

The garbage collector throws out old versions of world state when they
are no longer needed.

I imagine a GUI layout tool that allows the user to diagram a set of
sources, filters, and sinks and compiles that diagram into Haskell.

-Alex-

___________________________________________________________________
S. Alexander Jacobson                   i2x Media  
1-212-697-0184 voice                    1-212-697-1427 fax






Reply via email to