[Haskell-cafe] New version of itself

Alex Belanger i.caught.air at gmail.com
Sat Jun 4 14:30:07 UTC 2016

Before I go into crazy suggestions, have you looked at the Writer monad?

On Jun 4, 2016 9:25 AM, "martin" <martin.drautzburg at web.de> wrote:
> Hello all,
> I find myself frequentlly writing types like this
> data Logger a l = Lgr {
>   runLogger :: a -> Log l -> (Log l, Logger a l)
>   }
> The purpose is to give a logger a chance to carry an internal state. It
could e.g. choose to log only every n
> invocations. To do this it must keep track of how many times it has been
called. I want to leave such things private to
> the Logger.
> (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
> to it. Should I just not worry?
> (2) I can write a combinator which creates a Logger from a list of
Loggers. Since each Logger potentially returns a new
> version of itself, I must always re-assemble the combined logger from all
the returned new versions. I am worried that
> this is a costly operation, particularly when most Loggers just return
themselves unaltered. I don't have any hard
> numbers about the performance penalty though.
> These Loggers are used in a discrete-event-simulation and they will get
called many times (once for each event), but
> only occastionally actually write to the Log.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160604/65935274/attachment.html>

More information about the Haskell-Cafe mailing list