Original-Via: uk.ac.ox.prg; Wed, 6 Nov 91 09:30:57 GMT
[EMAIL PROTECTED] writes:
| There were two small bugs in the solution of Mark Jones:
No, I think they were Ok (after my slight correction).
But I can see why it might look confusing at first -- we naturally tend
to think of functional composition f . g as meaning "first apply g and
then apply f to the result". But you're forgetting about lazy evaluation!
What actually happens when we attempt to compare trees (u :^: v) and
(x :^: y) (applied to some ``comparison continuation'', o) is described
by:
(comp u x . comp v y) o = comp u x (comp v y o)
So the comparison between u and x *is* done first and the comparison
between v and y will only take place in the special case where u==x.
| This keeps the traversal order and stops evaluation when the first
| non-EQ has been found.
Which is exactly the behaviour I've just described.
Your approach is equivalent to mine, but I prefer to use the standard
functional composition (.) instead of introducing a new operator (@).
Putting it another way, my approach uses lazy evaluation where yours
requires explicit conditionals.
Hope that sorts things out!
Mark