I have a complex and recursive data structure which I have simplified to the following:
data Node = Node { value :: Integer, next :: Node } deriving (Show,Eq)
Given the following expressions:
--Create a circular structure
a = Node 1 b
b = Node 0 a --Tie the knot
c = Node 1 b --Another structure which points to b
The expressions a
and c
are conceptually equal: they both represent a node which holds the value 1 and points to the expression b. My question is: how do I check that they are indeed equal in a Haskell expression? If I evaluate a == c
it will keep evaluating sub-elements in the circular structure forever.
Is it possible to perform such a comparison in Haskell?
EDIT: In my case, I am trying to compare the two for inspection/debugging purposes. But another reason to do this could be for unit testing.