[swift-evolution] [Proposal] Decoupling Floating Point Strides from Generic Implementations
Dany St-Amant
dsa.mls at icloud.com
Tue Mar 1 05:41:20 CST 2016
> Le 1 mars 2016 à 05:56, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> a écrit :
>
>> If one were looking for a quick and dirty fix, the same kind of math used in this rough solution (let value = start + count * interval) could be adopted back into the current generic implementation.
>
> I notice that `start + count * interval` would actually work with `Int`, too.
>
> I wonder if we might be better off introducing a sub-protocol of `Strideable` which can advance several increments at a time:
>
> protocol RandomStrideable: Strideable {
> func advancedBy(n: Self.Distance, times: Int) -> Self
> }
>
> extension RandomStrideable {
> func stride(to end: Self, by: Distance) -> RandomStrideTo<Self> { ... }
> func stride(through end: Self, by: Distance) -> RandomStrideThrough { ... }
> }
>
> `Double` and `Int` can both conform to `RandomStrideable`; types which cannot do this (*are* there any types which cannot do this?) can conform to `Strideable`.
>
> Alternatively, if we actually *prefer* the repeated-advance implementation and we're only using this multiplication-based one because we have to, `Strideable` can be the new multiplication-based protocol and `IncrementalStrideable` can be a subprotocol which supports repeated-advance.
I was thinking about something similar, but as precise Strideable (direct increment ok) and impreciseStrideable (multiplicative must be used). But my main question is reversed, beside Double what other type/concept would require the multiplicative approached?
Dany
More information about the swift-evolution
mailing list