Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    OK, I'll look into that (and comment on it later). But what do you think about the idea of using the pattern? Commented Aug 13, 2013 at 23:17
  • 1
    @tieTYT I think the pattern itself is a very good idea; the State monad in general is a useful code-structuring tool for pseudo-mutable algorithms (algorithms that are immutable but emulate mutability). Commented Aug 14, 2013 at 0:05
  • 2
    +1 for noting that this pattern is essentially a Monad. However, I disagree that it is good idea in a language that actually have mutability. Monad is a way to provide the capability of globals/mutable state in a language that does not allow mutation. IMO, in a language that does not enforce immutability, the Monad pattern is just mental masturbation. Commented Aug 14, 2013 at 1:15
  • 6
    @LieRyan Monads in general actually have nothing at all to do with mutability or globals; only the State monad specifically does (because that's what it in particular is designed to do). I also disagree that the State monad is not useful in a language with mutability, although an implementation relying on mutability underneath might be more efficient than the immutable one I gave (although I'm not at all sure about that). The monadic interface can provide high-level capabilities that are not otherwise easily accessible, the stateBind combinator I gave is a very simple example of that. Commented Aug 14, 2013 at 3:32
  • 1
    @LieRyan I second Ptharien's comment -- most monads are not about state or mutability, and even the one that is, is specifically not about global state. Monads actually work quite well in OO/imperative/mutable languages. Commented Aug 14, 2013 at 14:11