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

Re: Pattern bindings



Original-Via: uk.ac.nsf; Mon, 4 Mar 91 17:24:50 GMT
Date: Mon, 4 Mar 91 09:23:05 MST
From: Joe Fasel <jhf@chaco.c3.lanl.gov>
To: haskell <haskell%edu.yale.cs@yalevm.ycc.yale.edu>
Subject: Re: Pattern bindings
Original-Sender: jhf%gov.lanl.c3.chaco%edu.yale.ycc.yalevm%edu.yale.cs@yale.edu
Sender: haskell-request@cs.glasgow.ac.uk

     [Simon]
| >       ... 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

  [Kevin]
| 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.

Consider

	y | y > 2	=  3
	  | otherwise	=  1

Wouldn't you want this to be equivalent to

	y = if y > 2 then 3 else 1

?  Of course, this definition isn't very useful, since it binds
y to bottom.  What about

	(x:xs) | length xs > 0  =  ys

?  How is this different from

	(x:xs@(_:_)) = ys

?  I grant that these definitions are peculiar, and if Kevin says
that they complicate the compiler, I'm certainly willing to consider
disallowing them, but we probably should not think we are losing
nothing by doing so.  It would appear that we are invalidating
some program transformations.

--Joe