[Haskell-cafe] Haskell RPC

Bjorn Bringert bringert at cs.chalmers.se
Mon May 29 21:35:39 EDT 2006


On May 25, 2006, at 11:00 AM, Joel Reymont wrote:

> Folks,
>
> I'm curious about how the following bit of Lisp code would  
> translate to Haskell. This is my implementation of Lisp RPC and it  
> basically sends strings around, printed "readably" and read on the  
> other end by the Lisp reader. If I have a list '(1 2) it prints as  
> "(1 2)" and becomes '(1 2) again when read on the other end.
>
> I'm wrote a couple of macros to make the job of defining the RPC  
> easier. def-remote-class defines the main (server) class as well as  
> the client (proxy) class.
>
> def-remote-method creates the server method as well as a proxy  
> method that sends data over and possibly waits for results and  
> returns them (depending on the :async or :sync qualifier). My Lisp  
> RPC code runs on top of UDP, looks good and works well. I have a  
> soft spot for Haskell in my heart, though, so I wonder how I would  
> go about implementing the same architecture in Haskell.
>
> This is an example from my test harness:
>
> (define-test remote-basic
>   (def-remote-class remote (server) ())
>   (def-remote-method sum :sync ((self remote) (a fixnum) (b integer))
>                      (declare (ignorable ip port))
>                      (+ a b seqnum))
>   (let* ((port (+ 1000 (random 50000)))
>          (server (make-instance 'remote
>                                 :port port))
>          (client (make-instance 'remote-proxy
>                                 :host (host-address)
>                                 :port port)))
>     (assert-equal '(6) (sum client 1 2 :seqnum 3))
>     (stop server)
>     (stop client)
>     ))
>
> I think I can send Haskell code over the wire to be read on the  
> other side just like I do with Lisp. The part that baffles me is  
> being able to provide an interface that lets one easily define  
> remote classes and methods.
>
> I totally hate Template Haskell because I find it incomprehensible  
> and I'm not going to compare it to Lisp macros. Is there a way to  
> do it without TH?
>
> Also, it seems to me that the only way to deal with variable  
> numbers of differently typed arguments is to use the HList approach  
> which is quite heavy machinery, IMO.
>
> Any suggestions?
>
> 	Thanks, Joel
>
> P.S. The Haskell Cafe has been a bit quiet lately so I do mean to  
> stir it up some. I think this example shows the advantage of  
> dynamically-typed languages.  I'm also genuinely interested in  
> possible Haskell solutions.

Hi Joel,

the attached example is a simple RPC library. It uses show and read  
for serialization, and some type class tricks to allow functions with  
different arities. This is essentially the HaXR (http:// 
www.haskell.org/haxr/) API, but without the XML, HTTP and error  
reporting stuff.

/Björn

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simplerpc.hs
Type: application/octet-stream
Size: 2188 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060529/8ba93e1d/simplerpc.obj


More information about the Haskell-Cafe mailing list