Re: [swift-evolution] About the PermutationGenerator

2016-01-06 Thread Jordan Rose via swift-evolution
I've bounced this idea off of Dave and Dmitri internally, so might as well put it out publicly: 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

Re: [swift-evolution] About the PermutationGenerator

2016-01-06 Thread Erica Sadun via swift-evolution
Thank you for this. Also, the book states: "SequenceType makes no requirement on conforming types regarding whether they will be destructively "consumed" by iteration. To ensure non-destructive iteration, constrain your sequence to CollectionType." Your magic DWIM Swift has generators (you

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dmitri Gribenko via swift-evolution
On Thu, Dec 31, 2015 at 2:01 PM, Susan Cheng via swift-evolution < swift-evolution@swift.org> wrote: > As I know SequenceType should have behaved as immutable structure and it > provides method to get a mutable GeneratorType which generates value from > start of sequence. Sequences are not

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Tino Heth via swift-evolution
> Those are collections. Collections can be iterated over multiple times. Speaking of the Fibonacci-numbers: Sure we can write an algorithm that iterates over them several times — it just won't ever finish the first iteration ;-) (only nitpicking — I just couldn't resist) Happy new year!

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dmitri Gribenko via swift-evolution
On Thu, Dec 31, 2015 at 3:04 PM, Susan Cheng wrote: > yes for sequences are not immutable. I get confused. > > no for sequences should be definition of lists of values. Just like > Fibonacci sequence, we can calculate the values form the start of the > Fibonacci sequence

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Susan Cheng via swift-evolution
I don't think so. As we don't say "Fibonacci collection", we know Fibonacci numbers are in order. But we can't tell the number immediately if I asked a specific index of Fibonacci sequence. The only way is calculate the sequence one by one from start. So we need the collection, and collection do

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Susan Cheng via swift-evolution
sequence can have more methods with it, we can find first five values of a sequence. but we don't do this with a generator struct Fibonacci: SequenceType { var first, second: Int func generate() -> AnyGenerator { var a = first var b = second return

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dmitri Gribenko via swift-evolution
On Thu, Dec 31, 2015 at 3:36 PM, Susan Cheng wrote: > I don't think so. > > As we don't say "Fibonacci collection", we know Fibonacci numbers are in > order. But we can't tell the number immediately if I asked a specific index > of Fibonacci sequence. The only way is

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dmitri Gribenko via swift-evolution
On Thu, Dec 31, 2015 at 3:51 PM, Tino Heth <2...@gmx.de> wrote: >> Those are collections. Collections can be iterated over multiple times. > Speaking of the Fibonacci-numbers: > Sure we can write an algorithm that iterates over them several times — it > just won't ever finish the first iteration

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Donnacha Oisín Kidney via swift-evolution
Just to add to that, it’s always seemed strange to me that to signify your sequence is multi-pass (i.e., to make it conform to CollectionType) you have to have it conform to Indexable. > On 31 Dec 2015, at 17:52, Erica Sadun via swift-evolution > wrote: > > I'm

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Erica Sadun via swift-evolution
It does seem that in Swift the concepts of collection, sequence, permutation, stream, etc are a bit muddled. -- E > On Dec 31, 2015, at 6:51 AM, Tino Heth via swift-evolution > wrote: > >> Those are collections. Collections can be iterated over multiple times. >

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 9:05 AM, Erica Sadun via swift-evolution > wrote: > > It does seem that in Swift the concepts of collection, sequence, permutation, > stream, etc are a bit muddled. This is a pretty vague critique. Do you have specifics, and suggestions that

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 9:52 AM, Erica Sadun wrote: > > I'm trying to work them out, so it's still muddled. > > Right now, I think SequenceType is better described as CollectionWalkType Why do you say so? > but that's kind of (1) a mouthful and (2) not entirely accurate.

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 10:52 AM, Donnacha Oisín Kidney > wrote: > > Just to add to that, it’s always seemed strange to me that to signify your > sequence is multi-pass (i.e., to make it conform to CollectionType) you have > to have it conform to Indexable. FWIW,

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 7:46 PM, Susan Cheng wrote: > > > How GeneratorType confirm to Equatable?? I don’t understand the question. In the code I posted there’s a working example of how a GeneratorType model can conform to Equatable.. > > struct Fib : SequenceType {

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 1:02 PM, Dave Abrahams via swift-evolution > wrote: > >> >> On Dec 31, 2015, at 10:52 AM, Donnacha Oisín Kidney > > wrote: >> >> Just to add to that, it’s always seemed strange to me

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread 鄭齊峯 via swift-evolution
if you try my modification, it will crash. struct Fib : SequenceType { var a: Int var b: Int var limit: Int func generate() -> FibGenerator { return Generator(a: a, b: b, limit: limit) } } let c = Multipass(Fib(a: 1, b: -1, limit: 10)) A SequenceType

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Susan Cheng via swift-evolution
I didn't explain correctly. let's take this: let c = Multipass(Fib(a: 1, b: -1, limit: 10)) this sequences should have results with [1, -1, 0, -1, -1, ...] So is c.startIndex.successor() equal to c.startIndex.successor().successor().successor()?? Dave Abrahams

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Susan Cheng via swift-evolution
How GeneratorType confirm to Equatable?? struct Fib : SequenceType { var a: Int var b: Int var limit: Int func generate() -> FibGenerator { return Generator(a: a, b: b, limit: limit) } } let c = Multipass(Fib(a: 1, b: -1, limit: 10)) -Susan 2016-01-01 11:17

Re: [swift-evolution] About the PermutationGenerator

2015-12-31 Thread Dave Abrahams via swift-evolution
> On Dec 31, 2015, at 8:22 PM, 鄭齊峯 via swift-evolution > wrote: > > if you try my modification, it will crash. Only because your Sequence genereates an arithmetic underflow. I don’t understand what point you’re trying to make > > struct Fib : SequenceType { >

[swift-evolution] About the PermutationGenerator

2015-12-30 Thread Susan Cheng via swift-evolution
PermutationGenerator confuses me that it's confirm to both of SequenceType and GeneratorType. Should it replace by PermutationSequence and PermutationGenerator? Also, we should have a PermutationCollection because we can: public struct PermutationCollection : CollectionType { public

Re: [swift-evolution] About the PermutationGenerator

2015-12-30 Thread Kevin Ballard via swift-evolution
We have plenty of examples of GeneratorTypes that also conform to SequenceType. There's no harm in it, and it saves having to declare a separate type that consists solely of a generate() method that returns the generator. In fact, the stdlib automatically derives the generate() method for any