<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thank you for this. Also, the book states: "<code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(128, 128, 128); font-family: Menlo, monospace; word-wrap: break-word;">SequenceType</code><span style="color: rgb(65, 65, 65); font-family: Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);" class="">&nbsp;makes no requirement on conforming types regarding whether they will be destructively "consumed" by iteration. To ensure non-destructive iteration, constrain your&nbsp;</span><em style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(65, 65, 65); font-family: Helvetica, Arial, sans-serif;" class="">sequence</em><span style="color: rgb(65, 65, 65); font-family: Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);" class="">&nbsp;to&nbsp;</span><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(128, 128, 128); font-family: Menlo, monospace; word-wrap: break-word;">CollectionType</code><span style="color: rgb(65, 65, 65); font-family: Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);" class="">."</span></div><div class=""><br class=""></div><div class="">Your magic DWIM Swift has <b class="">generators</b> (you call it a destructive iteration type) and <b class="">collections</b> (indexable, re-addressable types). I'm trying to wrap my head these. I interpret the former as f() -&gt; U, with a progression of accesses with no memory that maps to a known type, and the latter being f(index) -&gt; V, where index belongs to a fixed index set and maps to the collection's contents.</div><div class=""><br class=""></div><div class="">What confuses me is that both of these seem to my inexperienced mind to be operations not types. You point out that a SequenceType doesn't actually concretely exist ("Again, no concrete type would ever conform to SequenceType; it's just something you can use as a generic constraint.") If I were describing these, I'd call them <i class="">sequence generating functions</i> and <i class="">collection walk functions</i>. The former would allow potentially non-terminating streams including random number generation, signal generation (for example sin or square waves), or soliciting user input. The latter would offer any kind of iteration or permutation.</div><div class=""><br class=""></div><div class="">I'm not a language person (well not *that* kind of languages person) and I'm not up to date on the particular terms of art that apply here, as I learned when it came to suggesting alternatives to associated type, but it seems like these words don't really describe the things you guys are giving us.</div><div class=""><br class=""></div><div class="">Does this better explain my confusion?</div><div class=""><br class=""></div><div class="">-- Erica</div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Jan 6, 2016, at 10:37 AM, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">I've bounced this idea off of Dave and Dmitri internally, so might as well put it out publicly:</div><div class=""><br class=""></div><div class="">In Magic DWIM Swift, there would only be two types that you'd ever conform to: a destructive iteration type (today's "Generator"), and a multi-pass indexed type (today's "Collection"). Some&nbsp;<i class="">operations</i>&nbsp;can meaningfully use either one (like forEach or maxElement); these operations go on a general "traversable" type (today's "Sequence").</div><div class=""><br class=""></div><div class="">In this world, both GeneratorType and CollectionType are refinements of SequenceType (i.e. any GeneratorType "is-a" SequenceType), including the necessary default implementations. Maybe we rename some of the protocols in the process. Again, no concrete type would ever conform to SequenceType; it's just something you can use as a generic constraint.</div><div class=""><br class=""></div><div class="">We can't actually do this today because it creates a circularity between SequenceType and GeneratorType that the compiler can't handle. I'm pretty sure it's possible to change the compiler's protocol checking logic to allow this, though.</div><div class=""><br class=""></div><div class="">Anyway, that's that idea. At the very least it helped me clear up my thoughts about Sequence, Collection, and Generator back when I was first learning them.</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><div class="">P.S. This idea falls apart if someone comes up with a model (concrete type) for SequenceType that isn't a Collection or Generator. I wasn't able to think of one back when I was originally thinking about this, but of course that doesn't mean there isn't one. (Infinite collections are interesting as discussed on the "cycle" thread, but it's not the sequence/generator distinction that's really meaningful there.)</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 9:52, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I'm trying to work them out, so it's still muddled.</div><div class=""><br class=""></div><div class="">Right now, I think&nbsp;<font face="Menlo" class="">SequenceType</font>&nbsp;is better described as&nbsp;<font face="Menlo" class="">CollectionWalkType</font>&nbsp;but that's kind of (1) a mouthful and (2) not entirely accurate.&nbsp;</div><div class=""><br class=""></div><div class="">Moving back a step:&nbsp;<font face="Menlo" class="">SequenceType</font>&nbsp;is defined as: "A type that can be iterated with a `for`...`in` loop." But it says nothing about whether that loop ever terminates and many stdlib sequence functions currently don't make sense (at least if they're not lazy) with respect to infinite sequences, which should probably be "<font face="Menlo" class="">StreamType</font>" not sequences. A couple of examples:</div><div class=""><ul class=""><li class="">Here's my fib:&nbsp;<a href="http://swiftstub.com/189513594/" class="">http://swiftstub.com/189513594/</a></li><li class="">And here's Oisin's user-input sequence: &nbsp;<a href="https://gist.github.com/oisdk/2c7ac33bf2188528842a" class="">https://gist.github.com/oisdk/2c7ac33bf2188528842a</a></li></ul></div><div class="">Both of these are theoretically filterable, but they aren't dropLast-able, suffix-able, properly split-able, etc.</div><div class=""><br class=""></div><div class="">Hopefully that's enough of a starting point to indicate where my thinking is at and what I'm trying to think through when it comes to this. -- E</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 10:09 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Dec 31, 2015, at 9:05 AM, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">It does seem that in Swift the concepts of collection, sequence, permutation, stream, etc are a bit muddled.<br class=""></blockquote><br class="">This is a pretty vague critique. &nbsp;Do you have specifics, and suggestions that address them?<br class=""><br class=""><blockquote type="cite" class=""><br class="">-- E<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Dec 31, 2015, at 6:51 AM, Tino Heth via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Those are collections. &nbsp;Collections can be iterated over multiple times.<br class=""></blockquote>Speaking of the Fibonacci-numbers:<br class="">Sure we can write an algorithm that iterates over them several times — it just won't ever finish the first iteration ;-)<br class="">(only nitpicking — I just couldn't resist)<br class=""><br class="">Happy new year!<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class="">-Dave<br class=""><br class=""></div></div></blockquote></div><br class=""><span id="cid:CB35B16C-4004-4CCD-B338-F41B396501AD@localhost">&lt;open.gif&gt;</span><span class="" style="float: none; display: inline !important;">&nbsp;</span><span class="" style="float: none; display: inline !important;">_______________________________________________</span><br class=""><span class="" style="float: none; display: inline !important;">swift-evolution mailing list</span><br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote><div class=""><br class=""></div></div></div></div></div></blockquote></div><br class=""></body></html>