<p dir="ltr">Before I go into crazy suggestions, have you looked at the Writer monad?</p>
<p dir="ltr">On Jun 4, 2016 9:25 AM, "martin" <<a href="mailto:martin.drautzburg@web.de">martin.drautzburg@web.de</a>> wrote:<br>
><br>
> Hello all,<br>
><br>
> I find myself frequentlly writing types like this<br>
><br>
> data Logger a l = Lgr {<br>
> runLogger :: a -> Log l -> (Log l, Logger a l)<br>
> }<br>
><br>
> The purpose is to give a logger a chance to carry an internal state. It could e.g. choose to log only every n<br>
> invocations. To do this it must keep track of how many times it has been called. I want to leave such things private to<br>
> the Logger.<br>
><br>
><br>
> (1) I know that this is not an unusal thing to do, but it has an OO feel to it. Is there a more functional alternative<br>
> to it. Should I just not worry?<br>
><br>
> (2) I can write a combinator which creates a Logger from a list of Loggers. Since each Logger potentially returns a new<br>
> version of itself, I must always re-assemble the combined logger from all the returned new versions. I am worried that<br>
> this is a costly operation, particularly when most Loggers just return themselves unaltered. I don't have any hard<br>
> numbers about the performance penalty though.<br>
><br>
> These Loggers are used in a discrete-event-simulation and they will get called many times (once for each event), but<br>
> only occastionally actually write to the Log.<br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</p>