|
|
|
|
|
by howling
2989 days ago
|
|
All these discussions of "=" are missing the point. The notation "x = x + 1" is awful because at lhs x denotes a reference to an integer while at rhs x denotes the value hold by the reference. If you know C, it is similar to the difference between an integer pointer *x and an integer x. As an illustration, here are two programs that are doing the same thing, one in C and one in Haskell. #include <stdio.h>
int main() {
int x = 0;
x = x + 1;
printf("%d\n", x);
return 0;
}
import Data.IORef
main :: IO ()
main = do
xref <- newIORef 0
x1 <- readIORef xref
writeIORef xref (x1 + 1)
x2 <- readIORef xref
print x2
|
|