In these examples, we can identify the constructor (capitalized first letter) on the LHS and so we are trained to know that it is a pattern match. The original point related to number specialness was that "1 = 2" is not easily identifiable as a pattern match because there are no explicit constructors. The literal "1" here is neither an "explicit constructor" nor a binding symbol.

-harendra

On 24 February 2017 at 10:48, Jeff Clites <jclites@mac.com> wrote:
This works too:

    Nothing = Just "hello"

so you get the same effect even without any literal number specialness.

Even this:

    Just x = Nothing

also "works" until you force evaluation of x, as an irrefutable (lazy) pattern match. So in a way, you could view the first case as a lazy pattern match in which there is nothing you could possibly force, so there's no way to manifest the pattern match failure.

Just another way of looking at it.

JEff

On Feb 23, 2017, at 7:00 PM, Brandon Allbery <allbery.b@gmail.com> wrote:

It is, yes. (Literal numbers in patterns occasionally have unexpected type ramifications as a result; and occasionally others, since the compiler rewrites the pattern match into a guard. It's one of those things that Just Works 99% of the time and then makes you tear your hair out.)

On Thu, Feb 23, 2017 at 9:56 PM, Harendra Kumar <harendra.kumar@gmail.com> wrote:
My first guess was a pattern match, but it sounded a bit odd because there is no explicit constructor in case of numbers.  If there were an explicit constructor it would have been easier to imagine this as a pattern match. This seems to be a weird side effect of the special handling of numbers.

-harendra

On 24 February 2017 at 07:37, Brandon Allbery <allbery.b@gmail.com> wrote:
On Thu, Feb 23, 2017 at 9:05 PM, Harendra Kumar <harendra.kumar@gmail.com> wrote:
Kids have this amazing ability to break any toy in minutes. I gave my seven year old daughter ghci to play with and in a little while she said it is broken:

>> let 1 = 2

>> 1

1

>> 

Earlier, I had explained to her about symbols and assigning values to symbols, and I said numbers are not symbols. But when she came up with this I could not explain what's going on. How can "1 = 2" be a valid equation? Am I missing something fundamental here, or it is just broken?

It's a pattern match. The match fails, but as it produced no bindings it cannot be observed and its success or failure is irrelevant. 

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net




--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
_______________________________________________
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.

_______________________________________________
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.