Date: 2013-04-20 04:53 am (UTC)
winterkoninkje: shadowcrane (clean) (Default)
The reader monad with just ask isn't dynamic scope; it's just "global" variables. Adding local then allows you to have multiple stages of "globality"; i.e., it's a way to lie about there being a join operation on reader monads... or, well, not lie so much as bend the truth by giving local views of the global state (including the const somethingElseEntirely view).

The thing with dynamic scope is all about mutation IMO. I guess you could call the reader monad with local a form of dynamic scope, but I don't think that's really appropriate. For example, with dynamic scope you can use a loop to perform a bunch of mutation and then view the effects of that after the loop exits (so long as you don't exit the current stackframe). Can you achieve this with the reader monad? Bear in mind that every time you call local you're explicitly pushing a new "stackframe" which gets popped when the second argument returns.

You can certainly model parts of dynamic scope with the reader monad, but that's because you can model both of them by explicitly passing immutable state around. The reader monad doesn't introduce the reasoning difficulties that dynamic scope does. Even if you're trying to model DS, the details of making that model explicit will get in the way of the reasoning difficulties. There's nothing wrong with dynamic scope— except when that's not what you want.
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
Account name:
If you don't have an account you can create one now.
HTML doesn't work in the subject.


Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.



April 2013

14151617 181920

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 21st, 2017 03:12 am
Powered by Dreamwidth Studios