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

Alexey Muranov alexey.muranov at gmail.com
Sun Feb 26 00:08:58 UTC 2017


Can be added to Nitpicks then :) :

  https://wiki.haskell.org/Nitpicks

Alexey.

On Sunday, February 26, 2017 at 12:25:17 AM UTC+1, David Feuer wrote:
>
> I firmly believe that making pattern matches in let and where clauses lazy 
> by default was a mistake in the Haskell Report. It's inconsistent with how 
> pattern matching works elsewhere in the language, and also makes a strange 
> distinction between outer and inner pattern matches. Unfortunately, it's 
> way too late to fix that mistake.
>
> On Feb 24, 2017 12:09 AM, "Harendra Kumar" <harendr... at gmail.com 
> <javascript:>> wrote:
>
>> CCing the list. I guess you intended to cc but forgot.
>>
>> On 24 February 2017 at 09:27, <o... at cs.otago.ac.nz <javascript:>> wrote:
>>
>>> In Erlang, the equivalent of a let fails.
>>> 1> 1=2.
>>> ** exception error: no match of right hand side value 2
>>>
>>> In SML, the equivalent of a let fails.
>>> - val 1 = 1;
>>> - val 1 = 2;
>>>
>>> uncaught exception Bind [nonexhaustive binding failure]
>>>   raised at: stdIn:2.5-2.10
>>>
>>> The problem is not that let 1 = 2 ... is *legal* but that
>>> - the compiler is  *silent* about it
>>> - the runtime is *silent* about it.
>>> Compiling the little program
>>>
>>>   main = let 1 = 2 in print "hi"
>>>
>>> I expected that the compiler would be silent but that
>>> there would be some sort of "matched failed" error at
>>> run time.  Silly me.
>>>
>>>
>>> The thing is, it is not just bindings that bind no variables
>>> that act as if they were not there.
>>>
>>>   main = let [x] = [1,2] in print "hi"
>>>
>>> also compiles silently and runs without error.  Change it to
>>>
>>>   main = let [x] = [1,2] in print ("hi" ++ show x)
>>>
>>> and you get a runtime error
>>>
>>> <object>: <source>: Irrefutable pattern failed for pattern [x].
>>>
>>> I wish the compiler would report an error something like
>>>
>>> "<location>: possibly failing match deleted
>>>              because it binds no live variables"
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> 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/20170225/d5470dbc/attachment.html>


More information about the Haskell-Cafe mailing list