The semantics of irrefutable pattern matching is given as,

case e0 of { ~p -> e ; _ -> e' }

=  let { y = e0 } 
   in
       let { x1' = case y of { p -> x1 } } 
       in ...

            let { xn' = case y of { p -> xn } }
            in
                e[x1'/x1,x2'/x2 .. ,xn'/xn]

x1,..,xn are all variables in p ; 
y,x1',...,xn' are completely new variables

(Pg. No. 22 , Haskell 1.2 )

Does this mean that whenever a variable from the pattern p is required
(i.e x1,..xn) y is pattern matched against p, and the required
variable is returned.

Consider the following eg.

Using the above tanslation ,

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

== let { y = (1,2) }
   in 
       let { x1' = case y of { (a,b) -> a }}
       in 
            let { x2' = case y of { (a,b) -> b }}
            in
                 x1' + x2'

So, when x1' + x2' is evaluated,
Is (1,2) pattern matched against (a,b) twice -- once for x1' and once
for x2' ??

    I feel this is what the above let translation indicates. 

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

-- Namrata
   [EMAIL PROTECTED]



Reply via email to