In section 4.4 of the Haskell Report (v1.2), a pattern binding of the form
p | g1 = e1
| g2 = e2
...
| gm = em
where { decls }
is given the translation
p = let decls in
if g1 then e1 else
if g2 then e2 else
...
if gm then em else error "Unmatched pattern"
This strikes me as a bit odd: It says that only the guards determine
which e to bind to p. To my mind, the e's should have some say
in the matter also. If g1 is True and p = e1 fails to match, then
I would expect the pattern matching to continue with the match
'| g2 = e2'.
Now that I look at it again, the translation seems to be saying that
'p' is a function of arity 0. If this is the committee's point of view,
then the translation is reasonable. But this parallel between pattern
binding and function definition is a bit shaky: pattern bindings can
bind any number of variables, while function definition always binds one.
Also, this interpretation of pattern binding seems to violate the
principle of correspondence. (The principle of correspondence states
that for any definition mechanism there should exist a corresponding
parameter binding mechanism, and vice versa.) There is no parameter
binding mechanism that corresponds to definition by general pattern
binding. The corresponding parameter binding mechanism would require
m actual values for 1 formal parameter and the system would choose the
correct actual value based on the guards associated with the formal
parameter.
So... why did the committee include general pattern binding? Is this
construct used enough to justify weakening of correspondence in
favour of strengthening the orthogonality of (function) definitions?
I tend to favour correspondence, so I was a bit sad to discover this.
Especially since I don't think of pattern binding as being a special
case of function definition.
Norm
--
Norman Graham Oklahoma State University
Domain: [EMAIL PROTECTED] Department of Computer Science
BangPath: 219 Mathematical Sciences Building
{cbosgd,rutgers}!okstate!norman Stillwater, OK USA 74078-0599