News for hackers. Stuff that matters.
Re:Dynamic Scoping in C++ by fiddlerwoaroof on Monday September 21, 2020 @01:57PM (#24546402)
Yeah, “12 factor apps” basically use dynamic scope for dependency injection. But, also, I believe the Reader typeclass in Haskell is basically equivalent to dynamic scope? Haskellers seem to use this and a lot of similar techniques (Free monads/mtl style) to work around the lack of dynamic scope :).
Re:Dynamic Scoping in C++ by jolmg on Monday September 21, 2020 @02:33PM (#24546823)
Reader is similar, but I wouldn't say equivalent, because only those things working in the Reader can use that environment. For example, when you have project A using project B using project C, you can't define a putStrLn such that project C can use it and be able to override its output stream from project A, while keeping B completely ignorant of that ability of putStrLn or that C even uses putStrLn.

Reader is like a middle-ground between dynamic-scoping and explicit passing of a context argument around as you would in a statically-scoped language.

Re:Dynamic Scoping in C++ by catern on Monday September 21, 2020 @04:26PM (#24548064)
Reader is like implicit parameters: dynamic scoping with static types. https://dl.acm.org/doi/10.1145/325694.325708
Re:Dynamic Scoping in C++ by jolmg on Tuesday September 22, 2020 @08:28AM (#24553661)
I know what Reader is, but my point still stands.
Re:Dynamic Scoping in C++ by catern on Tuesday September 22, 2020 @07:54PM (#24561433)
Okay... I wasn't suggesting you don't know what Reader is... you said:

>Reader is like a middle-ground between dynamic-scoping and explicit passing of a context argument around

I just wanted to point out that the-thing-which-Reader-is, is sometimes called "implicit parameters", and there are papers written about it.