[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pattern bindings



From: Kevin Hammond <kh@cs.glasgow.ac.uk>
Date: Sat, 2 Mar 91 03:54:24 GMT
To: haskell@cs.glasgow.ac.uk, simonpj@cs.glasgow.ac.uk
Subject: Re:  Pattern bindings
Sender: haskell-request@cs.glasgow.ac.uk

>	... where  y | y>2 = 3
>		     | y<2 = 1
>
> It is patent nonsense for y to be in scope in its own guard, because
> both alternatives are "self-fulfilling". 
>
> I THEREFORE PROPOSE to state that in pattern bindings the variables being
> bound are not in scope in the guard.  In function bindings the function
> arguments, but not the function itself, are in scope.
> 
> Any comments?		

I don't really agree that all such bindings are "patent nonsense" (just
that most of them are, and that simpler definitions exist for the ones
that aren't!).  However, these are a pain to handle in the compiler,
and also cause problems with the dynamic semantics [I think Cordy and I
found a neat solution (using two levels of recursion), but it would be
neater not to deal with this].  I would be happy with the proposal to
outlaw such bindings, unless someone can demonstrate an obvious need
for them.

Outlawing the use of functions in their own guards strikes me as being
much less sound, however, especially where the programmer is defining
overloaded operations.  For example, you would presumably outlaw the
following:

	(x:xs) == (y:ys) | x == y & xs == ys = True
			 | otherwise = False

as well as many more normal recursive definitions.

I would definitely vote AGAINST this part of the proposal!  I see no
semantic or pragmatic advantages to it.

Kevin