|
|
|
|
|
by S4M
4159 days ago
|
|
I agree about the benefits of isolating side effects and IO - I generally code in python, and my code tends to look like: def main_function(args):
data = get_data(args)
result = do_calculations(data)
push_results(result, args)
Where the function do_calculations is somewhat pure - no side effects, but I do use local variables that I modify inside the function.> You are right. In this case effects are not isolated. But in this particular script, there are no interesting things to move into a pure function. It does not mean that it wouldn't be the case in a more complex script. Well, I thought that the point of Haskell (of one of its points) is that it forces the programmer to declare whatever side effect in the type of the function. But here, there is no way to know that main, on top of printing stuff, also messes up with the directory and there is no type signature indicating it - in this example it's no big deal but I could write something like: main = do
rm "/"
sleep 1
die "Oooops my files!"
|
|
Even though Haskell doesn't distinguish different classes of IO actions, it still distinguishes IO actions from other kinds of actions (such as stateful actions as per your example), and pure computations and that provides a hell of a lot of bang for buck.
The Idris language has the notion of effect types [1] to make achieving the goal of categorising the kinds of effects being used in a function easier to deal with, but that uses the dependent capabilities of the language.
[1] http://eb.host.cs.st-andrews.ac.uk/drafts/eff-tutorial.pdf