3 ms·
Worse, I think it actually overwrites the fib he just defined with a function that simply pattern matches on 30 and returns 832040. In GHCI, trying that exampl
by ricree 15y ago
Worse, I think it actually overwrites the fib he just defined with a function that simply pattern matches on 30 and returns 832040.
In GHCI, trying that example with fib 29 results in a non exhaustive pattern error.
- ramchip 15y agoExactly; just like let 2+2=5 in 2+2 amusingly returns 5.
- samstokes 15y agoYes, that line doesn't redefine the expression 2+2 as the author suggests; rather, it redefines the operator + as a function which only works on 2 and 2, and returns 5 for those arguments. e.g. Prelude> let 2+2=5 in 2+3 *** Exception: <interactive>:1:5-9: Non-exhaustive patterns in function +
- lelf 15y agoAnd, considering syntactic sugar for operators, fib and (+) examples are quite alike Prelude> let (+) 2 2 = 5; 4 + 2 = 42 in [2 + 2, (+) 4 2, 0 + 3] [5,42,*** Exception: <interactive>:1:5-29: Non-exhaustive patterns in function + Prelude> let fib 0 = 1 in fib 0 1