<div dir="auto"><div>Honestly, we could probably have positive numbers mean "do this number exactly" and negative numbers mean "use this as a hint". For instance:<div dir="auto"><br></div><div dir="auto">filter p arr = fromListN (negate $ length arr) $ Prelude.filter p $ toList arr</div><div dir="auto"><br></div><div dir="auto">This is an increase in definedness, since normally most implementations would error when provided a negative length.</div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020, 09:11 chessai . <<a href="mailto:chessai1996@gmail.com" target="_blank" rel="noreferrer">chessai1996@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I agree with others who have stated that the interpretation as a hint is bad for performance. My intuition has always been that we pre-allocate an array of length N, fill that in with a recursive function while accumulating the length, and rejecting anything incorrect. <div dir="auto"><br></div><div dir="auto">I think the motivation behind it being a hint is still mostly a mystery to me, until I can find some discussion. I can see how a hint might be useful from the perspective of the desugarer, but for people who are calling fromListN in source code, this seems much less intuitive, if not potentially useful.</div><div dir="auto"><br></div><div dir="auto">It might be illuminating if we could find some discussion about why this decision was made, since there might be something more I'm not considering. As it stands, my intuition (and that of most library authors I know, and most libraries I have seen) does not align with that as a hint. E.g. if primitive were to switch to treating N as a hint, it would require a majour version bump, and also it would be a place where a size hint would be most unwelcome because of perf.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020, 7:02 AM Bardur Arantsson <<a href="mailto:spam@scientician.net" rel="noreferrer noreferrer" target="_blank">spam@scientician.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 28/02/2020 04.40, Zemyla wrote:<br>
> I'm kind of the opposite. I think the number given to fromListN should<br>
> be a "size hint", not a redundant coding of the size of the list given.<br>
> <br>
<br>
One option would be to have a<br>
<br>
   data Size = Hint Int<br>
             | Exact Int<br>
<br>
as a parameter and let the user specify desired behavior. (Assuming it's<br>
easy to accomodate either.)<br>
<br>
Regards,<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div></div></div>