On Monday, October 18, 2010 17:54:50 Nick Sabalausky wrote: > "Jonathan M Davis" <jmdavisp...@gmx.com> wrote in message > news:mailman.715.1287449256.858.digitalmar...@puremagic.com... > > > One word: monads. > > > > Now, to get monads to work, you're going to have to be fairly organized > > about > > it, but that would be the classic solution to not being able to have or > > alter > > global state and yet still be able to effectively have global state. > > Oh yea, I've heard about them but don't have any real experience with them. > Any FP experts know whether or not monads are known to be constructible > from purely-FP building blocks? I always assumed "no", and that monads > really just came from a deliberate compiler-provided hole in the whole > purity thing, but maybe I'm wrong? (That would be quite interesting: > constructing impurity from purity.)
You can think of a monad as an extra parameter which is passed to each function and holds the global state. It isn't a hole in purity at all. For instance, it's how Haskell manages to have I/O and yet be functionally pure. You don't need the compiler's help to do monads - it's just easier if you have it. - Jonathan M Davis