Another query (-:
Mark Carroll
mark@chaos.x-philes.com
Wed, 1 Aug 2001 20:03:01 -0400 (EDT)
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))
The show is fine; it's the add that's confusing me. Where we have,
grow list = (Node False rest)
where
(Node _ rest) = add list
I don't really understand what's going on with this binding and matching
using "where", so I'm not seeing how the True and False values are
managing to propagate up to being results of grow as they do, e.g.:
> grow End
F <>
> grow (grow End)
F T <>
I have Hudak, Peterson, Fasel's gentle introduction to Haskell 98, and
Thompson's "Craft of Functional Programming" book - maybe I just missed
something in them? Is it easy to explain what's going on with this "where"
behaviour so that I could figure out what "grow"'s results are without
evaluating examples?
-- Mark