I have conquered the State monad

Jul 17, 2008 16:42

and lived to tell the tale.

Leave a comment

Comments 4

badoingdoing July 17 2008, 22:25:34 UTC
haskell ftw?

Reply

ellisbben July 18 2008, 18:27:16 UTC
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.

Reply


bozjoma July 18 2008, 16:10:51 UTC
What did you do?

Reply

ellisbben July 18 2008, 18:33:31 UTC
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.

Reply


Leave a comment

Up