[swift-evolution] [Re-Review] SE-0104: Protocol-oriented integers

plx plxswift at icloud.com
Thu Feb 23 09:33:27 CST 2017


+1 on most of it, with some minor quibbles.

First quibble: between `Number` and `Arithmetic` I’d prefer `Arithmetic`; this is 50/50 aesthetics and concern about clarity vis-a-vis `(NS)Number`, `(NS)DecimalNumber`, and so on.

Next quibble: `Magnitude` being defined as the “absolute value” of the underlying type seems a bit nonsensical if e.g. `Number` is intended to be adoptable by complex numbers (let alone quaternions, matrices, and whatnot). What *would* a conforming complex # implementation be expected to return as e.g. `(1-i).magnitude`? For the intended use this seems like it needs to be moved out of the basic `Number`/`Arithmetic` protocol into a new protocol.

Final quibble: is there an official stance as to whether or not `Number/`Arithmetic` is allowed to have non-commutative multiplication? I see would prefer any policy on this be explicitly documented.

If `Number`/`Arithmetic` *is* intended to allow adopters with non-commutative multiplication, then it’s seemingly missing an overridable method:

- this exists: `x *= y` (presumably equivalent to `x = x * y`)
- this doesn't: `x =* y` (presumably equivalent to one of `x = y * x` *or* `y = x * y`, your preference)

…(alternative operator names are fine, the important bit is an in-place multiplication-from-the-left). Not necessary, but still nice to have for non-commutative adoptees.

PS: I suspect this ship has *long* sailed but I suspect that it would be better in the long run to go the route of `Addable`, `Multipliable`, etc., and use typealiases to define common groupings thereof; note that once you remove `Magnitude`, the only difference between:

- `Number` (as defined)
- `typealias Number = Equatable & ExpressibleByIntegerLiteral & Addable & Multipliable`

…would be `init?<T : BinaryInteger>(exactly source: T)`.

Although this is an extra method and thus extra “semantics”, I think there’s a perfectly-reasonable argument that—at least informally—the *semantics* of `init?<T : BinaryInteger>(exactly source: T)` are already-implied by the adoption of `ExpressibleByIntegerLiteral`; in fact, are there any types that *could* reasonably adopt `ExpressibleByIntegerLiteral` but *could not* reasonably implement `init?<T : BinaryInteger>(exactly source: T)`? 

Anyways, that’s my 2c on this: the Integer-related aspects seem fine, but I have quibbles vis-a-vis the foundational protocol.

> On Feb 17, 2017, at 7:45 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello Swift community,
> 
> The re-review of SE-0104 "Protocol-oriented integers" begins now and runs through February 25, 2017. This proposal was accepted for Swift 3, but was not implemented in time for the release. The revised proposal is available here:
> 
> 	https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md <https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md>
> 
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> 
> 	https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:
> 
> 	Proposal link:
> 		https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md
> 	
> 	Reply text
> 
> 	Other replies
> 
> What goes into a review?
> 
> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> 
> 	• What is your evaluation of the proposal?
> 	• Is the problem being addressed significant enough to warrant a change to Swift?
> 	• Does this proposal fit well with the feel and direction of Swift?
> 	• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> 	• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> 
> More information about the Swift evolution process is available at
> 
> https://github.com/apple/swift-evolution/blob/master/process.md
> 
> Thank you,
> 
> -Joe Groff
> Review Manager
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170223/ec37b537/attachment.html>


More information about the swift-evolution mailing list