
On Jan 29, 2007, at 16:38 , Ross Paterson wrote:
On Fri, Jan 26, 2007 at 01:51:01PM +1100, Donald Bruce Stewart wrote:
Binary: high performance, pure binary serialisation for Haskell
--------------------------------------------------------------------- -
The Binary Strike Team is pleased to announce the release of a new, pure, efficient binary serialisation library for Haskell, now available from Hackage:
tarball: http://hackage.haskell.org/cgi-bin/hackage-scripts/ package/binary/0.2 darcs: darcs get http://darcs.haskell.org/binary haddocks: http://www.cse.unsw.edu.au/~dons/binary/Data-Binary.html
Remind me again: why do you need a Put monad, which always seems to have the argument type ()? Monoids really are underappreciated.
I don't know if that's the main reason, but monads give you do- notation, which can be very nice when you are doing a long sequence of puts. Here's an example from the tar package [1]: putHeaderNoChkSum :: TarHeader -> Put putHeaderNoChkSum hdr = do let (filePrefix, fileSuffix) = splitLongPath 100 (tarFileName hdr) putString 100 $ fileSuffix putOct 8 $ tarFileMode hdr putOct 8 $ tarOwnerID hdr putOct 8 $ tarGroupID hdr putOct 12 $ tarFileSize hdr putOct 12 $ let TOD s _ = tarModTime hdr in s fill 8 $ ' ' -- dummy checksum putTarFileType $ tarFileType hdr putString 100 $ tarLinkTarget hdr -- FIXME: take suffix split at / if too long putString 6 $ "ustar " putString 2 $ " " -- strange ustar version putString 32 $ tarOwnerName hdr putString 32 $ tarGroupName hdr putOct 8 $ tarDeviceMajor hdr putOct 8 $ tarDeviceMinor hdr putString 155 $ filePrefix fill 12 $ '\NUL' I guess mconcat [putX, putY, ... ] would work too, but the syntax is not quite as nice. /Björn [1] http://www.cs.chalmers.se/~bringert/darcs/tar/