Haskell graph data type representation
Posted
by John Retallack
on Stack Overflow
See other posts from Stack Overflow
or by John Retallack
Published on 2010-05-06T23:43:20Z
Indexed on
2010/05/06
23:48 UTC
Read the original article
Hit count: 136
I want to represent a graph in Haskell in the following manner:
For each node I want to store it's value and a list of adjacent nodes,the problem which i'm having difficulties with is that I want the adjacent nodes to be stored as references to other nodes.
For example: I want node ny to be stored as („NY“ (l p)) where l and p are adjacent nodes,and not as („NY“ („London“ „Paris“)).
I tried something like this :
data Node a = Node { value :: a
, neighbors :: [Node a]
}deriving (Show)
let n1 = Node {value=1, neighbors=[n2]}
let n2 = Node {value=1, neighbors=[n1 n3]}
let n3 = Node {value=1, neighbors=[n2]}
But i get en error in let,What am I doing wrong ?
© Stack Overflow or respective owner