Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

equal sign with haskell literals

What exactly happens in GHCi when I load a file with a line that says: 0=1 ?

I was expecting that this would give an error but it doesn't seem to do anything at all. Does it do anything?

I assume it's equivalent in GHCi to just saying "let 0=1". What does that do?

like image 793
user2744010 Avatar asked Sep 03 '13 17:09

user2744010


1 Answers

The 0 in your let binding is actually a pattern match on the literal 0. I wasn't sure what was going on at first too, but you can confirm this by using strict pattern matching like so:

Prelude> :set -XBangPatterns 
Prelude> let !0 = 1 in 0
*** Exception: <interactive>:13:5-10: Non-exhaustive patterns in pattern binding
like image 75
jberryman Avatar answered Oct 14 '22 16:10

jberryman