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

David Feuer david.feuer at gmail.com
Sat Feb 25 23:23:37 UTC 2017


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" <harendra.kumar at gmail.com> wrote:

> CCing the list. I guess you intended to cc but forgot.
>
> On 24 February 2017 at 09:27, <ok at cs.otago.ac.nz> 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/e53bd073/attachment.html>


More information about the Haskell-Cafe mailing list