[Haskell-cafe] Multi groupby with foldl' and Map.insertWithKey

Jan-Willem Maessen jmaessen at alum.mit.edu
Wed Dec 28 20:38:04 UTC 2016


On Wed, Dec 28, 2016 at 3:21 PM, Olaf Klinke <olf at aatal-apotheke.de> wrote:

>
> > Am 28.12.2016 um 19:40 schrieb Jan-Willem Maessen <jmaessen at alum.mit.edu
> >:
> >
> > A caution on this alternative: the first component of the tuple won't be
> strict enough and you'll leak space.  I think the proposed solution is
> better.  Note that you *don't* necessarily need the strictness annotation
> on healthTopics – this shifts around when the list append gets run but
> won't change space much.
> >
> > -Jan-Willem Maessen
> Thanks for clarifying this, Jan-Willem. So there ought to be stricter
> versions of the newtype wrappers in Data.Monoid. Even then, the tuple is
> not strict. Will that also leak space?
>

Yes, the fact that the tuple is strict means that Sum's strictness doesn't
matter (and Sum is a newtype, so strictness doesn't really come into play).


> I just thought the (Sum Int,[String]) type was a neat example of instance
> deriving.
>

Indeed!  And if I were hacking up a one-shot script I'd probably do it that
way.


>
> Cheers,
> Olaf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161228/32e2e760/attachment.html>


More information about the Haskell-Cafe mailing list