[Haskell-cafe] Haskell RPC
Joel Reymont
joelr1 at gmail.com
Thu May 25 14:00:03 EDT 2006
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.
--
http://wagerlabs.com/
More information about the Haskell-Cafe
mailing list