[Haskell-beginners] Implementation question about directed acyclic graph
Christian Sperandio
christian.sperandio at gmail.com
Fri May 8 13:30:56 UTC 2015
Hi,
I’m learning the Bayesian networks and I want to write my own implementation.
So, I started implementing t a DAG in Haskell but I’ve got some questions about the best way to do it in a functional mind.
I’m thinking about a DAG implementation avoids duplicate information. So, I imagined this implementation:
data Node a = Node { event :: a, proved :: Bool, nodeID :: Int }
type Connections = M.Map Int [Int]
data Graph a = Empty
| Gragh { nodes :: M.Map Int (Node a), nextID :: Int, connections :: Connections }
My idea is to yield an ID for each node and use this ID for connections. Thus, I can have the same events connected many times without duplicate the event data.
And when I have to change a node state, I don’t need to search all occurrences in the graph.
Am I on the right way ?
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150508/e800861c/attachment.html>
More information about the Beginners
mailing list