Yes. At long last it clicked and I realized that every (State s a) monad corresponds to a program in some imperative language which returns a value of type a using mutable state of type s.
I wrote a simple stack machine (something that involves a fair amount of side effects) in a programming language that forces you to build a layer of abstraction around any side effects.
While extra complexity involved in causing side effects may sound like a negative, when most of your code has no side effects, you can analyze the output of functions the same way you would analyze an equation-- whenever you run into some value external to the function, you go back and look at the definition of that value. In contrast, when a program uses lots of data which was produced by side effects, analysis of it must involve making sure that you know when the data was last changed and by what.
Comments 4
Reply
Reply
Reply
While extra complexity involved in causing side effects may sound like a negative, when most of your code has no side effects, you can analyze the output of functions the same way you would analyze an equation-- whenever you run into some value external to the function, you go back and look at the definition of that value. In contrast, when a program uses lots of data which was produced by side effects, analysis of it must involve making sure that you know when the data was last changed and by what.
Reply
Leave a comment