[Haskell-cafe] 1 = 0?

Brent Yorgey byorgey at seas.upenn.edu
Tue Jun 17 11:08:33 UTC 2014


On Tue, Jun 17, 2014 at 03:25:10AM -0700, Alexey Muranov wrote:
> Is this the expected behavior that
> 
>     1 = 0
> 
> does not raise any error?  What does this mean?

The general syntax of assignments is

  pattern = expression

One most often uses a pattern consisting of a single variable, but any
pattern will do.  (For example, try writing [x,y,z] = [1,2,3] as a
top-level declaration and see what happens!)  1 is a pattern which
matches the number 1.  0 is obviously an expression.  Of course, the
pattern 1 does not match the expression 0.  However, binding is lazy:
for example, writing [x,y] = [1,2,3] does not in and of itself cause
an error; it will only cause an error if you try to use x or y.
However, since the pattern 1 contains no variables, there is no way to
ever force the pattern-matching to actually take place.

So 1 = 0 just sits there, sort of like an ugly, angry dog who wants to
bite people except that it is locked in a cage with no door.
Occasionally people walking by look at it pityingly, but mostly no one
pays it any attention.

-Brent


More information about the Haskell-Cafe mailing list