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

Harendra Kumar harendra.kumar at gmail.com
Fri Feb 24 05:08:43 UTC 2017


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"
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170224/5d925105/attachment.html>


More information about the Haskell-Cafe mailing list