Wednesday, August 29, 2012

rpc-framework #1: Contravariance & Typeclasses

Suppose we have a typeclass:
 class Sendable a b | a -> b, b -> a where  
   send :: a -> IO ()  
   receive :: IO b  
Ideally we should have an instance for functions:
 class (Sendable a' a, Sendable b b') => Sendable (a -> b) (a' -> IO b') where  
This has contravariant narrowing though. Down the line, it will run into problems. Solution: split sendable into two definitions, one for sendable and one for receivable.

Wednesday, August 8, 2012

A remote language

     Last year when programming a database language in Haskell I found myself writing a lot of redundant and unsafe code for sending data across a network. Programming in enterprise java made me realize the usefulness of the service/rmi framework that it gives you. It also seems to be one of the few good reasons to use java over language X. There are of course plenty of drawbacks to network blind rpc, but the widespread acceptance of java's rmi seems to imply that a significant portion of the time people don't care, and that these drawbacks can be remedied by an understanding of the mechanics of rpc. The addition of such an rpc system to Haskell would surely boost it's prototyping usability. While there already exist plenty of rpc packages available for Haskell, most of them seem geared towards interfacing with other languages, which really didn't solve my problem of sending arbitrary data across the network safely.    

    Thus, I wrote my own RPC system. I wanted something that would be useful for prototyping large production code quickly, and also for quickly adding network capabilities to existing programs for programmers not very well versed in networking already. Given that this is Haskell, I wanted to be able to send functions across the network as well as pure data. This is really what rpc-framework solves. It is quite difficult serializing functions in a compiled lazy language, so I quickly gave up on the idea of sending them verbatim. Rather, I send links to the functions, as anonymous RPC calls. Actions work similarly. There is a lot of type level programming magic going on here, which I will definitely explain in the future. For now, please enjoy and report any bugs/missing features:

More info on github
Tutorial on hackage