[swift-evolution] [Pitch] Requiring proactive overrides for default protocol implementations.
Erica Sadun
erica at ericasadun.com
Thu Apr 28 20:32:48 CDT 2016
> On Apr 28, 2016, at 6:20 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> On Thu, Apr 28, 2016 at 6:44 PM, Erica Sadun <erica at ericasadun.com <mailto:erica at ericasadun.com>> wrote:
> Can you give me a specific example of where this approach fails for you?
>
> -- E
>
>
> Sure, I'll describe one (renaming some things for clarity and stripping out the meat of the code, because it's not relevant and because it's not elegant)--
>
> In one file, I have:
>
> ```
> class PortedTransfom {
> // this class was ported from C++
> // it transforms input FP values to output values in a complicated way
> // it's a standalone entity and the algorithm is even under patent
> // (not owned by me, though it's legal for me to use it for my purposes)
> // for this reason, this ported code lives in its own file
> }
> ```
>
> In another file, I have:
>
> ```
> class MyAsinhTransform {
> // this class was written by me
> // nothing earth-shattering here
> }
>
> class MyLogTransform {
> // also written by me
> }
>
> class MyLinearTransform {
> // also written by me
> }
> ```
>
> Transforming values one-at-a-time isn't fast enough, so in another file, I have:
>
> ```
> import Accelerate
>
> protocol AcceleratedTransform {
> func scale(_: [Double]) -> [Double]
> func unscale(_: [Double]) -> [Double]
> // other functions here
> // some are already implemented in PortedTransform, though
> }
> extension AcceleratedTransform {
> // default implementations for some functions
> // but not `scale(_:)` and `unscale(_:)`, obviously
> }
>
> extension MyAsinhTransform : AcceleratedTransform {
> // use BLAS to implement scale(_:) and unscale(_:)
> // and override some default implementations
> }
>
> extension MyLogTransform : AcceleratedTransform {
> // use BLAS to implement scale(_:) and unscale(_:)
> // and override some default implementations
> }
>
> extension MyLinearTransform : AcceleratedTransform {
> // use BLAS to implement scale(_:) and unscale(_:)
> // and override some default implementations
> }
>
> extension PortedTransform : AcceleratedTransform {
> // use BLAS to implement scale(_:) and unscale(_:)
> }
> ```
I think I'm missing something here in terms of a question. Your imported stuff is your imported stuff.
Your extension implements "required" elements but not scale or unscale.
If you extend MyAsinhTransform, you do required but not override for scale/unscale. You do required override for anything you replace from AcceleratedTransform.
What is BLAS? And what are you specifically asking about?
-- E, apologizing for not understanding
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160428/605b0bae/attachment.html>
More information about the swift-evolution
mailing list