I have a complex and recursive data structure that I have simplified as follows:
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 aand are cconceptually equal: both of them are a node that contains the value 1 and points to the expression b. My question is: how can I verify that they are really equal in a Haskell expression? If I evaluate a == c, he will continue to evaluate sub-elements in a circular structure forever.
Can this comparison be done in Haskell?
EDIT: In my case, I am trying to compare these two for verification / debugging purposes. But another reason to do this may be for unit testing.
source
share