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

Re: Pattern Binding



Date: Fri, 29 May 1992 14:37:26 +0200
From: Simon L Peyton Jones <simonpj@dcs.glasgow.ac.uk>
Sender: haskell-request@dcs.glasgow.ac.uk
To: kh@dcs.glasgow.ac.uk
Cc: brian@comp.vuw.ac.nz, norman@a.cs.okstate.edu, haskell@dcs.glasgow.ac.uk
Subject: Re: Pattern Binding


There are two issues going on here.

1. Should pattern variables be permitted in the guard?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Haskell's reply: yes, but the result is always bottom.

After all, 

	- you need to evaluate the guard to discover which 
		RHS to bind the pattern to
	- but you need to choose a particular RHS in order to evaluate
		the guard

Consider:

	(x,y) | x>1       = (2,3)
	      | otherwise = (0,4)

(this example is mildly amusing, because it has two incomparable fixpoints
other than x=y=bot)



2. If the RHS chosen by the first guard to return True does not match
the pattern, should the next RHS with a valid guard by tried.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We didn't consider this during the design process.  Since the
guards can be simply True, one could write rather odd programs like:

	[x,y] | True = e1
	      | True = e2
	      | True = e3

which would pick the first of e1,e2,e3 to evaluate to a list of two elements.
I'm far from convinced that this is a feature though.

Simon