Simon Marlow wrote:
|
|Graeme Moss wrote:
|
|> Is there anything wrong with the following program?
|> 
|> > test :: Bool
|> > test | True = True
|> > test = False
|
|The two bindings for 'test' are
|pattern bindings (according to the syntax from the report), and hence
|constitute two separate declarations of the same variable, which is
|illegal.

Aha, yes, you are right, though I cannot see anywhere that says it is
illegal to define a caf more than once, nor anywhere that says it is
illegal to define completely overlapping function declarations, the
latter of which ghc does actually compile.  Only non-contiguous
function bindings for the same function, uneven number of patterns,
and non-linear patterns, are defined as illegal.

I am "nit picking" I know, but it would be good to have as tight a
definition of Standard Haskell as possible.

I went from:

> where f x | nastyBusinessDetected x = "Some warning string."
>       f x = "No warning."

to:

> where f | nastyBusinessDetected = "Some warning string."
>       f = "No warning."

because I changed some other part of the code that meant I didn't need
"x" anymore, and couldn't see why this new code shouldn't work.

Here is a distinction between cafs (pattern bindings) and functions
(function bindings), which I don't like.  However, I do not want to
lose the ability to say the useful:

> (x:xs) = ys

or gain the ability to say the meaningless:

> (x:xs) ys = zs

So there really is a distinction between the two.

Theoretically, it may be possible to unify these two definitions by
replacing the "x p11 ... p1k" of a function binding with "p10 p11
... p1k" and complaining if k>0 and p10 is not a trivial pattern with
"cannot pattern match on a function".  But then, this probably
introduces more confusion than it removes. :-)

Cheers,

Graeme.




Reply via email to