Misleading strictness annotations in Data.List.NonEmpty

David Feuer david.feuer at gmail.com
Fri Jan 8 20:03:00 UTC 2021


I think removing the annotations that don't change anything can be done in
a GHC MR without discussion on this list. I think the discussion on things
that change strictness can and should continue here.

On Fri, Jan 8, 2021, 2:59 PM Oleg Grenrus <oleg.grenrus at iki.fi> wrote:

> I'd expect that anyone who uses mfix with NonEmpty as result would use
> explicit (and irrefutable) pattern matching.
>
> But yes, changing these might make some code break. I'm not confident at
> all it won't make some code less efficient too, by forcing the structure
> of NonEmpty too early.
>
> So I would like that this thread is only about changing `head` and
> `tail` and not let scope creep.
> OR we hold this and let Keith come up with more complete NonEmpty
> implementation change.
>
> - Oleg
>
> On 8.1.2021 21.50, Viktor Dukhovni wrote:
> > On Fri, Jan 08, 2021 at 09:44:31PM +0200, Oleg Grenrus wrote:
> >> Note also
> >>
> >> -- | @since 4.9.0.0
> >> instance Foldable NonEmpty where
> >>   foldr f z ~(a :| as) = f a (List.foldr f z as)
> >>   foldl f z (a :| as) = List.foldl f (f z a) as
> >>   foldl1 f (a :| as) = List.foldl f a as
> >>
> >>   -- GHC isn't clever enough to transform the default definition
> >>   -- into anything like this, so we'd end up shuffling a bunch of
> >>   -- Maybes around.
> >>   foldr1 f (p :| ps) = foldr go id ps p
> >>     where
> >>       go x r prev = f prev (r x)
> >>
> >>   -- We used to say
> >>   --
> >>   --   length (_ :| as) = 1 + length as
> >>   --
> >>   -- but the default definition is better, counting from 1.
> >>   --
> >>   -- The default definition also works great for null and foldl'.
> >>   -- As usual for cons lists, foldr' is basically hopeless.
> >>
> >>   foldMap f ~(a :| as) = f a `mappend` foldMap f as
> >>   fold ~(m :| ms) = m `mappend` fold ms
> >>   toList ~(a :| as) = a : as
> >>
> >> Plenty of irrefutable patterns.
> > Do any of these make "mfix" more usable for NonEmpty?  Or are they just
> > superfluous?  With just one constructor, is there any downside to an
> > irrefutable pattern?
> >
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20210108/56d83dfd/attachment.html>


More information about the Libraries mailing list