Pathological Answer

# Pathological Answer This is the answer to the following question: ## Pathological Question What is the bound value of pattern variable `$y` after matching the following two tuple patterns: Tuple pattern A: `((ho, $_, ($a, $a)), ($a, $a, $b), ($a, *$b))` Tuple pattern B: `($x, $x, $y)` ## Answer Let's take this step by step, matching each element of the two tuple patterns in turn. Match `(ho, $_, ($a, $a))` to `$x`. This succeeds with the following binding: `$x`: `(ho, $_, ($a, $a))` Match `($a, $a, $b)` to `$x`. Because `$x` is bound to a value, this becomes the same as matching: `($a, $a, $b)` to `(ho, $_, ($a, $a))` Which succeeds, binding: `$a`: `ho` `$b`: `($a, $a)` `$_` is an anonymous variable, so it is not bound (or bound to). Match `($a, *$b)` to `$y`. Because both `$a` and `$b` have bound values, this becomes the same as matching: `(ho, ho, ho)` to `$y` Which succeeds, binding: `$y`: `(ho, ho, ho)` So the overall match succeeds with the following bindings: `$x`: `(ho, $_, ($a, $a))` `$a`: `ho` `$b`: `($a, $a)` `$y`: `(ho, ho, ho)` And so `$y` is `(ho, ho, ho)`! Note If you got this right, you should really be using Pyke!
Copyright © 2007-2009 Bruce Frederiksen

Page last modified Mon, Oct 27 2008.