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

Brandon Allbery allbery.b at gmail.com
Fri Feb 24 03:15:19 UTC 2017


Literally the only use I've seen for this was a CCC puzzle. However, it is
the trivial case of something that is more useful: pattern matching the
result of an expression (say, a Data.Map.lookup when you know the key
exists).

pyanfar Z$ ghc -c -Wall Mu.hs

Mu.hs:3:1: Warning:
    Defaulting the following constraint(s) to type ‘Integer’
      (Eq a0) arising from the literal ‘1’ at Mu.hs:3:1
      (Num a0) arising from the literal ‘1’ at Mu.hs:3:1
    In the pattern: 1
    In a pattern binding: 1 = 2

Mu.hs:3:1: Warning: This pattern-binding binds no variables: 1 = 2


On Thu, Feb 23, 2017 at 10:11 PM, Harendra Kumar <harendra.kumar at gmail.com>
wrote:

> Are pattern matches which produce no bindings useful in any case? Will it
> be possible or a good idea for the compiler to produce warnings in such
> cases? This seems to be just a no-op.
>
> -harendra
>
> On 24 February 2017 at 08:30, Brandon Allbery <allbery.b at 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 at 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 at gmail.com>
>>> wrote:
>>>
>>>> On Thu, Feb 23, 2017 at 9:05 PM, Harendra Kumar <
>>>> harendra.kumar at 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 at gmail.com
>>>> ballbery at sinenomine.net
>>>> unix, openafs, kerberos, infrastructure, xmonad
>>>> http://sinenomine.net
>>>>
>>>
>>>
>>
>>
>> --
>> brandon s allbery kf8nh                               sine nomine
>> associates
>> allbery.b at gmail.com
>> ballbery at sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
>


-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170223/e848200f/attachment.html>


More information about the Haskell-Cafe mailing list