I want to read a big graph structure from hard disk in Haskell. The graph structure looks like this:
Every node has got a definition - a file describing what are the children and how are they connected (these graphs are serialized using Data.Serialize
.
Every node can have children. So if I've got file A.node
I can have directory A
containing children of A
node (in the form of <X>.node
files and directories).
I want to be able to traverse this graph using Haskell and load to memory and unserialize only needed files. So If I for example traverse the graph in the way of A->B->C
(where B
is child of A
etc), then Haskell should read files A.node
, A/B.node
and A/B/C.node
. The next time I traverse the graph, the files should NOT be read again, because we did it already.
How can I do this the best way?
There are libraries that give you a pure value that represents a full directory tree, and will only read those directories and file that are actually used. By virtue of lazy evaluation, the second time you access such a file it will already by in memory.
Check out directory-tree, especially the readDirectoryWithL
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With