SNA=Shah Namrata Abhaykumar

SNA   Consider the following eg.
SNA
SNA   Using the above tanslation ,
SNA
SNA   case (1,2) of { ~(a,b) = a + b ; _ -> 0 }
SNA
SNA   == let { y = (1,2) }
SNA      in 
SNA       let { x1' = case y of { (a,b) -> a }}
SNA       in 
SNA            let { x2' = case y of { (a,b) -> b }}
SNA            in
SNA                 x1' + x2'
SNA
SNA   So, when x1' + x2' is evaluated,
SNA   Is (1,2) pattern matched against (a,b) twice -- once for x1' and once
SNA   for x2' ??

It is matched twice, but this doesn't matter -- matching is side-effect-free.


SNA   But,
SNA       When (1,2) is pattern matched with (a,b) for the first time ,
SNA       bindings  for both a and b can be created. So when x2'is needed,
SNA       pattern matching need not be done - the binding created
SNA       during the first pattern match can be used.

In your example, yes, but consider the following:

case (1,2,undef) of { ~(a,b,~(c,d)) = a+b; _ -> 0 }

You have to delay the binding of c and d,
because the subpattern is still irrefutable after the translation
(and not a variable).

---
Stefan Kahrs

Reply via email to