Timeline for Write a program that makes 2 + 2 = 5
Current License: CC BY-SA 3.0
20 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 3, 2014 at 16:13 | comment | added | Ming-Tang | @JanDvorak Damn it, I always get that part wrong. | |
| Jun 4, 2014 at 21:46 | comment | added | David Conrad | It is rather too explicit. Better would be to redefine it in one place, and have the call in another, further down the stack. It isn't possible to compile a Haskell program with a modified version of the Haskell prelude, is it? | |
| Jun 4, 2014 at 13:10 | comment | added | GreenAsJade | I don't see why this gets so many votes. It doesn't make it appear that adding 2 + 2 gives the answer 5 at all. It's too explicit - big bzzzzzt! | |
| Jun 2, 2014 at 3:57 | comment | added | Luis Casillas | @user3217013 A let expression in Haskell defines a local variable to a specified value within the context of that expression. But "variable" here in fact encompasses not just things like x and y, but also infix operators like +, and values encompass not just things like 5 or "Hello World!", but also functions. When an expression is evaluated in Haskell, the variables' values are looked up in the nearest defining scope. So in this example, + is redefined, in the scope of this expression only, to a function that produces 5 when both arguments are 2. | |
| Jun 2, 2014 at 2:47 | comment | added | Ptival | @user3217013 You are just defining the function (+) using equational style, where you define what should happen when the first argument is 2 and the second is 2, and you don't define all the other cases (thus, an inexhaustive definition). Kind of case (x, y) of (2, 2) -> 5 | |
| Jun 2, 2014 at 2:27 | comment | added | user3217013 | @Jefffrey Thanks for your condescending comment, but I am actually well-versed in Haskell. I just have never seen this pattern before. | |
| Jun 2, 2014 at 2:19 | comment | added | sh03 | @user3217013 Learn Haskell, it's good for your heart. | |
| Jun 2, 2014 at 1:41 | comment | added | user3217013 | How does this even work? How is this actually allowed?! | |
| Jun 1, 2014 at 15:54 | comment | added | Davorak | let 2+2=5; x+y= x Prelude.+ y in 5+5 only redefines 2+2 and leaves the rest of addition alone. | |
| Jun 1, 2014 at 15:48 | comment | added | Tikhon Jelvis | I'm a fan of the where version: 2 + 2 where 2 + 2 = 5. It even pops up on t-shirts! It doesn't work in GHCi though :(. | |
| May 31, 2014 at 6:02 | comment | added | John Dvorak | @N0ir unfortunately, Genesis doesn't make for a valid Haskell code. Not even the first chapter. Not even the verse you mention. | |
| May 30, 2014 at 23:15 | comment | added | OutFall | that almost sounds like: "And God said let 2+2=5 in 2+2" )) | |
| May 30, 2014 at 18:33 | comment | added | John Dvorak | @SHiNKiROU shadow, not redefine | |
| May 30, 2014 at 18:31 | comment | added | Ming-Tang | The plus operator is a function, and let can redefine existing functions. let (+) 2 2 = 5 in (+) 2 2 | |
| May 30, 2014 at 17:59 | comment | added | Flonk | @JanDvorak haha, okay ಠ_ಠ | |
| May 30, 2014 at 17:53 | comment | added | John Dvorak | @Flonk I got it. That's why I used my look of disapproval ;-) | |
| May 30, 2014 at 17:50 | comment | added | Flonk | @JanDvorak Non-exhaustive patterns in function + - I'm defining a new function (+) here, and If I plug in anything that isn't 2+2 it will error because I never defined what should happen in that case. | |
| May 30, 2014 at 17:47 | comment | added | Hauleth | Define function named 2+2 that return 5 | |
| May 30, 2014 at 17:44 | comment | added | John Dvorak | What does let 2+2=5 in 5+5 do? ಠ_ಠ | |
| May 30, 2014 at 11:42 | history | answered | Flonk | CC BY-SA 3.0 |