|
|
|
|
|
by ridiculous_fish
4023 days ago
|
|
Here is a Haskell action, that has the effect of waiting for 5 seconds: sleep 5
This is in the IO monad and therefore impure. As we know, it is better to use pure functions when possible. Let us rewrite it as a pure function: seq $ [0..] !! 1000000000
This accomplishes the same thing with no side effects, and is therefore better. Please note that spinning up your CPU fan is not a side effect.Joking of course, but it does illustrate the point. Functions take time and time is user-visible, thus all functions are effectful in that way. And C programmers will roll their eyes at the idea that `getpid` has side effects, while allocating a million node linked list does not. Really this is just talking at cross purposes. Haskell's notion of purity and side effects lives not on the physical machine, but in a formalism, and ghc is its imperfect simulator. |
|