
----- Original Message -----
From: "Mark Carroll"
To:
I've made a bizarre little program that I don't understand the behaviour of. It's:
data BoolList = End | Node Bool BoolList
instance Show BoolList where show (Node False rest) = "F " ++ show rest show (Node True rest) = "T " ++ show rest show End = "<>"
grow list = (Node False rest) where (Node _ rest) = add list add End = (Node True End) add (Node truth rest) = (Node truth (add rest))
What "add list" does is adding a True to the end of the list, however, "grow list" will ignore the first element of the result, change it to False.... Main> Node True (Node False ( Node False (Node True End))) T F F T <> Main> grow(Node True (Node False ( Node False (Node True End)))) F F F T T <> in the example above, "add list" will return T F F T T <>, and then, "grow list" changes the first element to F. Hope this helps, Yao