[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Guards in pattern bindings
To: haskell@cs.glasgow.ac.uk
Cc: simonpj@cs.glasgow.ac.uk
Subject: Guards in pattern bindings
Date: Wed, 06 Mar 91 12:38:49 +0000
From: Simon L Peyton Jones <simonpj@cs.glasgow.ac.uk>
Sender: haskell-request@cs.glasgow.ac.uk
I sent a message proposing a clarification to the question of
which variables are in scope in a guard for a pattern binding.
Following a number of responses I now think I was wrong-headed.
The Report already states (Section 4.4.2, page 33) that
p | g1 = e1
| g2 = e2
(p is a pattern, gi are guards, ei are expressions) is equivalent to
p = if g1 then e1 else
if g2 then e2 else
error ""
So my example
y | y>2 = 3
| y<=2 = 1
is semantically equivalent to
y = if y>2 then 3 else 1
which is of course bottom.
So there is a perfectly well-behaved meaning for guarded pattern bindings,
and I withdraw my proposal. Sorry to consume your bandwidth unnecessarily.
Simon