Thinking about monad, it came to me the idea of a monad as the way to break with the Von Neumann architecture. The Von Neumann architecture uses a set of instructions (called program) to change the data in memory and the execution of each instruction of the program updates a program counter to know whom instruction is the next to execute.
If we think about the Von Neumann architecture as a monad, the bind operator (>>=) update the program counter. We can make a Monad that break Von Neumann architecture to do more in the bind. As an example, we can have a Monad that count the number of instructions executed in our programs.
But, when I tried to implement that Monad in haskell as:
data Counter a = Counter Integer a
deriving( Show )
instance Monad Counter where
(Counter n1 a) >>= f = let Counter _ b = f a
in (Counter (n1+1) b)
return a = Counter 1 a
I notice it'll break de Monads laws, e.g:
return x >>= f /= f x
do
a <- return 3
return a
do
return 3
The two blocks are the same because the monad laws, but they'll return something different because they have different number of instructions (sentences)
Do I made something wrong? or Is it not possible to have such Monad?