[swift-evolution] About the PermutationGenerator
Dave Abrahams
dabrahams at apple.com
Mon Feb 22 09:02:32 CST 2016
on Wed Jan 06 2016, Jordan Rose <jordan_rose-AT-apple.com> wrote:
> 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:
You don't really mean that :-)
> a destructive iteration type (today's "Generator"), and a multi-pass
> indexed type (today's "Collection"). Some operations can meaningfully
> use either one (like forEach or maxElement); these operations go on a
> general "traversable" type (today's "Sequence").
>
> 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.
If GeneratorType and CollectionType conform to SequenceType, then lots
of concrete types will conform. I think you just mean that none will
conform to SequenceType without also conforming to one of the others.
> 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.
Yes; the main obstacle is that our codegen model doesn't support it. It
has something to do with the way witness tables get passed to generic
functions.
> 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.
>
> Jordan
>
> 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.)
--
-Dave
More information about the swift-evolution
mailing list