
Am I right in thinking that there aren't currently any standard libraries for converting values to bitstreams and back, to be saved in files or squirted over network sockets or whatever to be resurrected later or elsewhere? I'd guess it would be hard to write, too - I've not noticed any introspection. How do people normally efficiently pass complex Haskell data structures to other co-operating Haskell processes? (I am thinking of something a bit like Java's serialisation.) -- Mark

Mark Carroll writes:
Am I right in thinking that there aren't currently any standard libraries for converting values to bitstreams and back, to be saved in files or squirted over network sockets or whatever to be resurrected later or elsewhere?
Can you use Read and Show? I mean, not ideal for all purposes, but very standard.
How do people normally efficiently pass complex Haskell data structures to other co-operating Haskell processes?
Well, 'efficiently' is a problem. :-) -kzm -- If I haven't seen further, it is by standing in the footprints of giants

On 21 Aug 2001, Ketil Malde wrote: (snip)
Can you use Read and Show? I mean, not ideal for all purposes, but very standard. (snip)
I figured it would be quite a waste having the computer convert the data to human-readable form and then parsing it again when a human's not going to be reading the intervening datastream. Even just converting the numbers to ASCII and back takes time when there's quite a few of them. (snip)
Well, 'efficiently' is a problem. :-)
Apparently so! (-: Thanks anyway. Of course, I can get by with an inefficient version where I have to write some pickling and unpickling code for lots of my types, until something better shows up! I assume it will someday. -- Mark

On Tue, 21 Aug 2001, Mark Carroll wrote:
I figured it would be quite a waste having the computer convert the data to human-readable form and then parsing it again when a human's not going to be reading the intervening datastream. Even just converting the numbers to ASCII and back takes time when there's quite a few of them. Of course, I can get by with an inefficient version where I have to write some pickling and unpickling code for lots of my types, until something better shows up! I assume it will someday.
I am not sure about the status for ghc but there is a Binary class (even with deriving) in the nhc compiler http://www.cs.york.ac.uk/fp/nhc98/libs/Binary.html a Native class in hbc http://www.cs.chalmers.se/~augustss/hbc/hbc_library.html#Native (For downloading hbc, read http://www.haskell.org/pipermail/haskell/2001-June/001331.html) A quick search for ghc Binary gave me this links which seems to provide a port nhc's Binary that works with ghc. http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/Bin... You could ask Sven Panne directly for details. I hope this helps, Patrik Jansson

Am I right in thinking that there aren't currently any standard libraries for converting values to bitstreams and back, to be saved in files or squirted over network sockets or whatever to be resurrected later or elsewhere?
There is a 'Bits' library supplied with ghc, but it only gives you word-at-a-time operations, and instances only really make sense for fixed-size types like Int, Word, Float, Double, etc. A few years ago I spent a while developing a 'Binary' library which gives true bit-stream operations, where basically you can serialise any data structure to an arbitrary-length bit-stream. This library is supplied with nhc98, and Sven Panne ported it to ghc. I also adopted Noel Winstanley's standalone tool 'DrIFT' for automatically deriving instances of the Binary class, which answers one of your other questions. It is pretty easy to extend DrIFT to derive any class you might design. Web references: Binary: ftp://ftp.cs.york.ac.uk/pub/malcolm/ismm98.html Binary/GHC: http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/Bin... DrIFT: http://www.cs.york.ac.uk/fp/DrIFT/ Regards, Malcolm

On Tue, 21 Aug 2001, Malcolm Wallace wrote: (snip)
A few years ago I spent a while developing a 'Binary' library which gives true bit-stream operations, where basically you can serialise any data structure to an arbitrary-length bit-stream. This library is supplied with nhc98, and Sven Panne ported it to ghc. I also adopted Noel Winstanley's standalone tool 'DrIFT' for automatically deriving instances of the Binary class, which answers one of your other questions. It is pretty easy to extend DrIFT to derive any class you might design. (snip)
Wow - that all looks great. I assume it's on its way to becoming a standard library with ghc and nhc? (-: Thanks very much! -- Mark

I also have done some work on a set of classes which will let you read in and write out XDR encoded data, (as is used in NFS and other rpc protocols) in a hopefully efficient manner. I am working on figuring out how to modify DrIFT to auto-derive instances of it. the near-term goal is an nfs server written in haskell (for a virtual filesystem) as well as an efficient on-disk format for data. Another side effect of this work is that the code also generates a unique hash which is only dependant on the type of the encoded data, the idea being that I can tag the beginning of on-disk data with it and have some degree of insured type-safety. John On Tue, Aug 21, 2001 at 08:22:01AM -0400, Mark Carroll wrote:
On 21 Aug 2001, Ketil Malde wrote: (snip)
Can you use Read and Show? I mean, not ideal for all purposes, but very standard. (snip)
I figured it would be quite a waste having the computer convert the data to human-readable form and then parsing it again when a human's not going to be reading the intervening datastream. Even just converting the numbers to ASCII and back takes time when there's quite a few of them.
(snip)
Well, 'efficiently' is a problem. :-)
Apparently so! (-: Thanks anyway.
Of course, I can get by with an inefficient version where I have to write some pickling and unpickling code for lots of my types, until something better shows up! I assume it will someday.
-- Mark
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@repetae.net ---------------------------------------------------------------------------
participants (5)
-
John Meacham
-
Ketil Malde
-
Malcolm Wallace
-
Mark Carroll
-
Patrik Jansson