thegravian
thegravian

Reputation: 448

Efficient Serializing of Recursive Data Structures in Haskell

I am currently working with some large Trie structures in Haskell that I build from a binary file. The process takes some time, and I was curious if there is a general-case approach to fast-ish (de)serialization of recursive data structures. For large files and large Tries, using the Show and Read classes is (much) slower than building the tries from scratch. Perhaps I'm doing it wrong.

The Trie is shaped like this:

type Trie e a = T e [Trie e a]

What are some good approaches to serializing a recursive structure like this? Also, what are some good approaches to this problem in general?

Upvotes: 7

Views: 456

Answers (2)

Ericson2314
Ericson2314

Reputation: 133

The link for deriving an instance of binary in the documentation is broken as stated in the comments of the question. But the file exists just at a new slightly different URL: http://darcs.haskell.org/packages/binary/tools/derive/BinaryDerive.hs

I haven't used it yet, but I think this does what you want.

Upvotes: 1

rampion
rampion

Reputation: 89123

A general purpose solution might be to implement Foldable and Unfoldable (hopefully the latter class exists).

Upvotes: 1

Related Questions