3 ms·
A side effect is anything not modeled that can affect the computation. Input is an obvious example, as it's impossible to predict the value of an input. Outpu
by hgsgm 3y ago
A side effect is anything not modeled that can affect the computation.
Input is an obvious example, as it's impossible to predict the value of an input.
Output is less obvious, but there is uncertainty like whether the filesystem is full.
The original Haskell style was to have a World object that was an input to every non-pure function.
- jibe 3y agoInput is an obvious example, as it's impossible to predict the value of an input. Do you mean this more abstractly or literally? In the example of PacMan, for every frame, the only possible input is nothing, left, right, up, or down. So you are be able to predict it is going to be one of those five, though not which one.
- mrkeen 3y ago> Do you mean this more abstractly or literally? >> Input is an obvious example, as it's impossible to predict the value of an input. > though not which one Literally.
- jibe 3y agoI’m asking as someone not familiar with function programming, so trying to learn, not be pedantic, btw! So because the possible input is not just a single value, it is not predictable. It doesn’t matter if the input was limited to a set of two values, or infinite, it is literally not predictable so therefore we don’t know the future state of the program?
- epgui 3y agoThat’s right! You can consider the user input a source of randomness even if it can only take two values, like heads or tails.
- TuringTest 3y agoThat is unpredictable, but not a side effect. Side effects are changes that are not declared as part of the function parameters. If you model the controller input as a function parameter, that's just a state argument, and FP can handle it declaratively just fine without having side effects.