BERT[-RPC] for Haskell
by marius a. eriksen (email@example.com)
The primitives provided are fairly elementary: for the client,
provides the capability to perform the RPC call, while the server's
serve is provided with a dispatch function providing the dispatching
logic for the server. Thus, one can imagine building higher level
abstractions on top of these primitives.
It's a cabal package, so
$ cabal configure && cabal install
should do the trick.
import qualified Data.ByteString.Lazy.Char8 as C import Data.BERT
Creating BERT terms is simple.
TupleTerm [BytelistTerm (C.pack "hello"), IntTerm 123]
Or by using the
showBERT $ ("hello", 123)
BERT class can also read terms back.
Right ("hello", 123) = readBERT . showBERT $ ("hello", 123)
import Data.BERT import Network.BERT.Client
Create a transport to the server endpoint, and issue a (synchronous) call with it.
t <- fromURI "bert://localhost:8000" r <- call t "calc" "add" ([123, 3000]::[Int]) case r of Right res -> print (res :: Int) Left _ -> putStrLn "error"
import Data.BERT import Network.BERT.Server
Create a transport from which to accept connections, and provide a dispatch function for incoming RPCs. The dispatch function is issued in a new thread for each incoming request.
main = do t <- fromHostPort "" 8080 serve t dispatch dispatch "calc" "add" [IntTerm a, IntTerm b] = return $ Right $ IntTerm (a + b) dispatch mod fun args = do return $ Left "no such m/f!"