[Haskell-beginners] Re: problem with System.Directory.Tree

Stephen Tetley stephen.tetley at gmail.com
Mon Jun 14 03:56:35 EDT 2010

Hello Anand

System.Directory.Tree is not a good candidate for serializing directly
- as you have found out, one of the constructors - Failed - carries an
IOException which cannot be serialized (IOExceptions may contain file
handles which are inherently runtime values).

Data.Binary is usually the best option for serialization. In your
case, you wont be able to make a 1-1 mapping between a runtime DirTree
and its on disk representation as you'll have to work out what to do
about 'Failed' - maybe you would want to only serialize the good
constructors - Dir and File - instead.

As you will have to coerce the data type a bit, I'd recommend using
Data.Binary to write the serialization, but rather than make instances
of Put and Get for DirTree instead give the serialize and deserialize
functions characteristic names e.g.
 serializeGoodTree / deserializeGoodTree.

Best wishes


More information about the Beginners mailing list