[Haskell-cafe] What does "1 = 2" mean in Haskell?
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
> 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
> Really, though, we probably shouldn't be putting incomplete pattern
> matches in
> our code :P
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe