Different ways to see a monad
While learning Haskell I have faced a lot of tutorials trying to explain what are monads and why monads are important in Haskell. Each of them used analogies so it would be easier to catch the meaning.
At the end of the day, I have end up with 3 differents view of what a monad is:
I don’t understand the definition of side effects [duplicate]
Possible Duplicate:
What is a “side effect?”
Are side-effects in Array’s “every”, or “some” bad?
I’ve always been taught that having side-effects in an if
condition are bad. What I mean is;
How is referential transparency enforced?
In FP languages, calling a function with the same parameters over and over again returns the same result over and over again (i.e. referential transparency).
Intuition behind why Rust’s io::stdin().read_line() relies on a side effect?
I’m reading the second chapter of the official Rust book as a pretty seasoned python programmer. As you can imagine, its been pretty jarring, but I’m learning.
Where do we put “asking the world” code when we separate computation from side effects?
According to Command-Query Separation principle, as well as Thinking in Data and DDD with Clojure presentations one should separate side effects (modifying the world) from computations and decisions, so that it would be easier to understand and test both parts.
Where do we put “asking the world” code when we separate computation from side effects?
According to Command-Query Separation principle, as well as Thinking in Data and DDD with Clojure presentations one should separate side effects (modifying the world) from computations and decisions, so that it would be easier to understand and test both parts.
Unit testing side effect-heavy code
I’m starting to write C++ code to run a robot, and I don’t know how to incorporate unit testing, if indeed I can. I have been provided with a library which allows the creation of “commands” for the robot, which are automatically scheduled and executed. The mechanism to create these commands is to subclass a command base class they provide, and implement virtual void Initialize()
, void Execute()
, and void End()
methods. These functions are run purely for their side effects, which do things to the robot (run motors, extend pistons, etc.). Because of this, I don’t really see anywhere to attach unit tests to the code, short of mocking the entire library so that I can check the virtual before and after states of the robot. Is there a way to unit test this that isn’t overly burdensome?
Side Effects Breaking Referential Transparency
Functional Programming in Scala explains a side effect’s impact on breaking referential transparency:
Why is reading from memory not a side-effect but reading from a file is?
What does exactly make reading from the process memory a pure operation? Suppose I created an array of 100 integers in the global memory and then took the 42th element of this array. It is not a side effect, right? So why is reading the same array of 100 integers from a file a side-effect?