With Swift 4 out, I’ve started using the numeric protocols quite a bit, and
they are great!

One thing I find myself wishing for is a protocol that extends Numeric
while also allowing division—a Field protocol, if you will. I have
implemented several algorithms generically over FloatingPoint because they
need division, which means they aren’t available for, eg., a Rational type.

Absent a Field protocol in the standard library, I can create one of my own:

protocol Field: Numeric {
  static func / (lhs: Self, rhs: Self) -> Self
}

And I can extend Float and Double and Float80 to conform easily enough.
However, I’d really like to write,

extension FloatingPoint: Field {}

and make every type which conforms to FloatingPoint (such as a third-party
Complex type), also conform to Field.

Is this potentially feasible? Would other people find it useful?

Nevin
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution
  • [swift-evolution] Retroactive ... Nevin Brackett-Rozinsky via swift-evolution

Reply via email to