<div dir="auto">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.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 8, 2021, 2:59 PM Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi">oleg.grenrus@iki.fi</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'd expect that anyone who uses mfix with NonEmpty as result would use<br>
explicit (and irrefutable) pattern matching.<br>
<br>
But yes, changing these might make some code break. I'm not confident at<br>
all it won't make some code less efficient too, by forcing the structure<br>
of NonEmpty too early.<br>
<br>
So I would like that this thread is only about changing `head` and<br>
`tail` and not let scope creep.<br>
OR we hold this and let Keith come up with more complete NonEmpty<br>
implementation change.<br>
<br>
- Oleg<br>
<br>
On 8.1.2021 21.50, Viktor Dukhovni wrote:<br>
> On Fri, Jan 08, 2021 at 09:44:31PM +0200, Oleg Grenrus wrote:<br>
>> Note also<br>
>><br>
>> -- | @since 4.9.0.0<br>
>> instance Foldable NonEmpty where<br>
>> foldr f z ~(a :| as) = f a (List.foldr f z as)<br>
>> foldl f z (a :| as) = List.foldl f (f z a) as<br>
>> foldl1 f (a :| as) = List.foldl f a as<br>
>><br>
>> -- GHC isn't clever enough to transform the default definition<br>
>> -- into anything like this, so we'd end up shuffling a bunch of<br>
>> -- Maybes around.<br>
>> foldr1 f (p :| ps) = foldr go id ps p<br>
>> where<br>
>> go x r prev = f prev (r x)<br>
>><br>
>> -- We used to say<br>
>> --<br>
>> -- length (_ :| as) = 1 + length as<br>
>> --<br>
>> -- but the default definition is better, counting from 1.<br>
>> --<br>
>> -- The default definition also works great for null and foldl'.<br>
>> -- As usual for cons lists, foldr' is basically hopeless.<br>
>><br>
>> foldMap f ~(a :| as) = f a `mappend` foldMap f as<br>
>> fold ~(m :| ms) = m `mappend` fold ms<br>
>> toList ~(a :| as) = a : as<br>
>><br>
>> Plenty of irrefutable patterns.<br>
> Do any of these make "mfix" more usable for NonEmpty? Or are they just<br>
> superfluous? With just one constructor, is there any downside to an<br>
> irrefutable pattern?<br>
><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>