<div dir="auto">There are at least two reasonable sorts of hint: upper bounds and lower bounds. For arrays, either can be useful, but upper bounds are especially nice in combination with resizing primitives (currently only available for SmallArray and ByteArray-backed arrays). For sequences, lower bounds are useful, but upper bounds aren't really.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020, 1:49 PM Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi" target="_blank" rel="noreferrer">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">My personal expectations may be different based on what the container in<br>
question is.<br>
Elsewhere in the discussion types in `primitive` and `vector` were<br>
mentioned.<br>
They are however different.<br>
<br>
Compare to C++ code snippets, which are all morally `fromList(N)`:<br>
<br>
std::array<int, 100> variantA;<br>
for (int i = 0; i < 100; i++) {<br>
primitive[i] = f(i);<br>
}<br>
<br>
// not good<br>
std::vector<int> variantB;<br>
for (int i = 0; i < 100; i++) {<br>
primitive.push_back(f(i));<br>
}<br>
<br>
std::vector<int> variantC;<br>
variantC.reserve(100);<br>
for (int i = 0; i < 100; i++) {<br>
primitive.push_back(f(i));<br>
}<br>
<br>
I'm not a fan of changing `fromListN` to be partial function, but if<br>
that change is carried on in `vector` there should be a variant which<br>
allows to `reserve` without worrying about partiality.<br>
<br>
- Oleg<br>
<br>
<br>
<br>
On 28.2.2020 4.53, Carter Schonwald wrote:<br>
> Hey everyone: <br>
> When you see fromListN as a function in a library, do you assume /<br>
> presume it’s expecting an exactly N element list ? Or do you<br>
> expect/tolerate other behavior ? <br>
><br>
> Should it reject shorter lists?<br>
><br>
> Should it truncate or reject longer lists? <br>
><br>
> A corner case of this came up in some bug discussion I was having<br>
> regarding vector, and I shall claim and or presume that most folks<br>
> assume exact size with prompt rejection of too long or too short. <br>
><br>
> Thoughts please ?<br>
><br>
> -Carter <br>
><br>
> _______________________________________________<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>
_______________________________________________<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>