[Haskell-cafe] What does "1 = 2" mean in Haskell?

Dan Burton danburton.email at gmail.com
Fri Feb 24 23:23:34 UTC 2017

Note that similar to the !Nothing example, a bang pattern surfaces the
error you'd expect

Prelude> :set -XBangPatterns
Prelude> let !1 = 2
*** Exception: <interactive>:2:5-10: Irrefutable pattern failed for pattern

So this exception is lurking about, but due to laziness and the equation's
irrelevance, it doesn't show unless you force it with strictness.

I think the real expectation mismatch here is that numbers are not bindable
symbols, so `let 1 = expr in 1` does not rebind 1 to be `expr` like a
beginner might think.

-- Dan Burton

On Thu, Feb 23, 2017 at 11:08 PM, Taeer Bar-Yam <taeer at necsi.edu> wrote:

> I think the usefulness of numeric / string literals as pattern matches is
> as
> part of larger matches (as someone mentioned), not by itself. But since (I
> assume) these things are defined recursively, it makes sense just to add
> it as a
> base-level pattern match.
> Furthermore, you would not want
> ```
> main = let 1 = 2 in print "foo"
> ```
> to error, since the pattern match is unused, and haskell is a lazy
> language.
> Really, though, we probably shouldn't be putting incomplete pattern
> matches in
> our code :P
>  --Taeer
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170224/41f7b72b/attachment.html>

More information about the Haskell-Cafe mailing list