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

David Feuer david.feuer at gmail.com
Sun Feb 26 04:43:22 UTC 2017


Yes, lazy patterns are useful. That's what we have the ~ syntax for!
You can always write

where
  ~(a, b) = ....

or whatever. I think a bang is good for a strict non-pattern binding, like

where
  !a = ....

because that's the unusual case, but I think it's bad for a strict
pattern binding, which is the *usual* case.

On Sat, Feb 25, 2017 at 10:28 PM, Ivan Lazar Miljenovic
<ivan.miljenovic at gmail.com> wrote:
> On 26 February 2017 at 10:23, David Feuer <david.feuer at gmail.com> 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.
>
> I've used that though in combination of guards where I call the
> (lazily evaluated) result only in cases where it's irrefutable.
>
>>
>> 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.
>>
>>
>> _______________________________________________
>> 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.
>
>
>
> --
> Ivan Lazar Miljenovic
> Ivan.Miljenovic at gmail.com
> http://IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list