Re:A Gentle Intro to Monads … Maybe?
by tel on Friday January 17, 2014 @12:09PM
(#7076917)
(1) Backtracking is easy with the state monad since you can snapshot your entire "world" without trouble and replay it as needed.
(2) Monads cause you to tag your types with effects that they are using. This means that your code is self-documenting about the side-effects it performs. In non-pure languages you still have to trust that the code isn't breaking convention, but it's a very powerful documentation methodology.
(3) Creation of arbitrarily complex effects via stacking. While your language might have state and even non-determinism, it probably doesn't have their combination built-in. Their combination forms a very nice backtracking, non-deterministic parser almost automatically (see a loonnngg comment of mine elsewhere in this thread).
(4) Optimization and compilation. While not directly possible with vanilla State, once you begin to use monads to represent effects it's easy to go back through and optimize your entire "language" by optimizing your monad implementations. You can even optimize them right into other targets like the Accelerate library which cross-compiles certain fragments of your Haskell—which look like mostly garden-variety normal Haskell—into GPU code.
Re:A Gentle Intro to Monads … Maybe?
by Mithaldu on Friday January 17, 2014 @12:27PM
(#7077060)
I guess what you're saying is that
1. a core implementation is simply more powerful.
and
2. my question doesn't really have much with the nature of monads to do.
(2) Monads cause you to tag your types with effects that they are using. This means that your code is self-documenting about the side-effects it performs. In non-pure languages you still have to trust that the code isn't breaking convention, but it's a very powerful documentation methodology.
(3) Creation of arbitrarily complex effects via stacking. While your language might have state and even non-determinism, it probably doesn't have their combination built-in. Their combination forms a very nice backtracking, non-deterministic parser almost automatically (see a loonnngg comment of mine elsewhere in this thread).
(4) Optimization and compilation. While not directly possible with vanilla State, once you begin to use monads to represent effects it's easy to go back through and optimize your entire "language" by optimizing your monad implementations. You can even optimize them right into other targets like the Accelerate library which cross-compiles certain fragments of your Haskell—which look like mostly garden-variety normal Haskell—into GPU code.