haskell bert implementation

14 views
Skip to first unread message

marius a. eriksen

unread,
Oct 28, 2009, 11:03:35 PM10/28/09
to BERT-RPC
hi — i have a preliminary implementation up:

http://github.com/mariusaeriksen/bert

it handles most of BERT/BERP, but not yet
the RPC protocol.

terms are a type, and has a typeclass supporting
conversion, with implementations for common
haskell datatypes already. this is akin to the
haskell JSON library. eg.,

> showBERT ((1.0::Float), 2, False, "hello")
TupleTerm [FloatTerm 1.0,BigbigintTerm 2,BoolTerm False,BytelistTerm
(Chunk "hello" Empty)]
> readBERT $ showBERT ((1.0::Float), 2, False, "hello") :: Either String Term
Right (TupleTerm [FloatTerm 1.0,BigbigintTerm 2,BoolTerm
False,BytelistTerm (Chunk "hello" Empty)])

and supports binary encoding via the Data.Binary
class.

encode $ showBERT ((1.0::Float), 2, False, "hello")
Chunk "\131h\EOTc" (Chunk "1.000000000000000e0\NUL\NUL\NUL\NUL\NUL\NUL
\NUL\NUL\NUL\NUL\NUL\NUL" (Chunk "o\NUL\NUL\NUL\SOH\NUL" (Chunk
"\STX" (Chunk "h\STXd\NUL\EOT" (Chunk "bert" (Chunk "d\NUL\ENQ" (Chunk
"false" (Chunk "k\NUL\ENQ" (Chunk "hello" Empty)))))))))

or a packet:

ghci> encode $ Packet $ showBERT ((1.0::Float), 2, False, "hello")
Chunk "\NUL\NUL\NULC" (Chunk "\131h\EOTc" (Chunk
"1.000000000000000e0\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL
\NUL" (Chunk "o\NUL\NUL\NUL\SOH\NUL" (Chunk "\STX" (Chunk "h\STXd\NUL
\EOT" (Chunk "bert" (Chunk "d\NUL\ENQ" (Chunk "false" (Chunk "k\NUL
\ENQ" (Chunk "hello" Empty))))))))))

marius a. eriksen

unread,
Oct 28, 2009, 11:07:44 PM10/28/09
to BERT-RPC
On Oct 28, 8:03 pm, "marius a. eriksen" <marius.erik...@gmail.com>
wrote:
>> readBERT $ showBERT ((1.0::Float), 2, False, "hello") :: Either String Term

err, rather.

> readBERT $ showBERT ((1.0::Float), 2, False, "hello") :: Either String (Float, Integer, Bool, String)
Right (1.0,2,False,"hello")

marius.

Tom Preston-Werner

unread,
Oct 29, 2009, 1:56:41 PM10/29/09
to BERT-RPC
On Oct 28, 8:03 pm, "marius a. eriksen" <marius.erik...@gmail.com>
wrote:
> hi — i have a preliminary implementation up:
>
>  http://github.com/mariusaeriksen/bert
>
> it handles most of BERT/BERP, but not yet
> the RPC protocol.

This is awesome! I've added it to the list of implementations at
http://bert-rpc.org. I'm excited to see how this project progresses.

Tom

marius a. eriksen

unread,
Nov 1, 2009, 5:43:35 PM11/1/09
to BERT-RPC
the library now has BERT-RPC client and server
support (synchronous only for now). as well as
some meaningful documentation.

http://github.com/mariusaeriksen/bert

i've tested it against ernie (and also with itself of
course) and it seems to work well.

caching is also not yet supported. what is the best
practice for dealing with unsupported actions?
caching is simple — the server and client can simply
ignore cache directives. for both streaming and
asynchronous requests i'm currently replying with
server error 0.

marius.

On Oct 29, 9:56 am, Tom Preston-Werner <mojo...@gmail.com> wrote:
> On Oct 28, 8:03 pm, "marius a. eriksen" <marius.erik...@gmail.com>
> wrote:
>
> > hi — i have a preliminary implementation up:
>
> >  http://github.com/mariusaeriksen/bert
>
> > it handles most of BERT/BERP, but not yet
> > the RPC protocol.
>
> This is awesome! I've added it to the list of implementations athttp://bert-rpc.org. I'm excited to see how this project progresses.
>
> Tom

Woo-Kyoung Noh

unread,
Nov 3, 2009, 6:19:01 AM11/3/09
to BERT-RPC
oh, really great .

On Nov 2, 7:43 am, "marius a. eriksen" <marius.erik...@gmail.com>

marius a. eriksen

unread,
Nov 4, 2009, 2:50:23 AM11/4/09
to BERT-RPC
and i've uploaded it to hackage now:

http://hackage.haskell.org/package/bert

so if you have haskell installed, it's a simple

$ cabal install bert

and you're set!

i also wrote a small erlang-syntax BERT term parser (it can parse any
BERT compatible erlang term in erlang syntax), and a little tool to
make calls which is probably useful to anyone playing with BERT. this
is included in the aforementioned cabal package.

(using tom's example calc.rb with ernie):

$ bert call bert://localhost:8000 calc add 123 456
reply: 579
$ bert call bert://localhost:8000 errorcalc add 123 456
error: ServerError {error, {user, 0, <<"RuntimeError">>,
<<"abandon hope!">>, [<<"/Users/marius/Loc..
$ bert call bert://localhost:8000 calc add "{1, test, [5,6,7]}" 456
error: ServerError {error, {user, 0, <<"TypeError">>,
<<"can't convert Fixnum into Array">>, ..

you get the idea.

marius.

On Nov 1, 2:43 pm, "marius a. eriksen" <marius.erik...@gmail.com>
Reply all
Reply to author
Forward
0 new messages