Another query (-:

Yao Guo yaoguo@cse.ogi.edu
Wed, 1 Aug 2001 17:54:29 -0700


----- Original Message -----
From: "Mark Carroll" <mark@chaos.x-philes.com>
To: <haskell-cafe@haskell.org>
Sent: Wednesday, August 01, 2001 5:03 PM
Subject: Another query (-:


> 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