Suggestion/proposal regarding std.logger candidate

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat May 24 20:10:21 PDT 2014


On Sat, 24 May 2014 11:42:30 +0000
HaraldZealot via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> The logger is very good and need thing. But has anybody an idea
> how to preserve purity of functions?
>

That's impossible if you're doing I/O. By definition, that has to access
mutable, global state. The only way to do it would be to go the Haskell route
and use something like monads - you'd have to basically pass an object around
which built up the logging messages without actually logging anything and then
have an impure function higher up (which is calling these pure functions) make
the function call which actually caused the queued up logging to be output.

Logging is basically anti-purity. So, unless you do something like I just
described (which I doubt much of anyone will), then logging anything in your
code means giving up purity.

- Jonathan M Davis


More information about the Digitalmars-d mailing list