on Sun Jan 29 2017, Jonathan Hull <jhull-AT-gbis.com> wrote:

> Shouldn’t “Number” be reserved for a foundation type similar to
> NSNumber?  Or would this protocol actually serve that purpose?

I don't think so.  What is the purpose of NSNumber?  I always viewed it
as being, approximately, a box that allows us to put numerical values
into NSArrays.

> I was planning to ask for a value type similar to NSNumber in phase 2.
> I built one for my own code (a struct around an enum which can be Int,
> Decimal, Rational, or Rational * π) and it is super useful for
> handling things like user input where the value could be an Integer or
> Float/Decimal, and I always want the highest precision until I ask for
> it in a particular form.  If it came in as an integer, I know I can
> present it as an integer, and vice versa with decimal numbers.

That sounds like exactly the right way to handle your scenario, and your
use case wouldn't be served by NSNumber.  If we invented an
NSNumber-like thing to serve your use case, it wouldn't serve someone
else's.

> Sometimes it is nice to be able to say: “The user gave me a number”
> and not really care about the underlying representation...

But it seems to me that you do care, very much, because you're trying to
avoid losing precision from one of several possible input formats.

I mean, if you wanted you could do this:

  struct AnyNumber {
    public init<N: Number>(_ n: N) {
      self._value = n
    }
    public func unwwrapped<N: Number>(as: N.Type) -> N? {
       return self._value as? N
    }
    private let _value: Any
  }

but there's not all that much you can do with something like this.

> Thanks,
> Jon
>
>> On Jan 27, 2017, at 4:50 PM, Max Moiseev via swift-evolution 
>> <[email protected]> wrote:
>> 
>> Renaming Arithmetic to Number (and having SignedNumber) might
>> actually end up being a win, since we need to provide SignedNumber
>> to maintain source code compatibility anyway.
>> 
>>> On Jan 27, 2017, at 8:34 AM, Xiaodi Wu via swift-evolution
>>> <[email protected] <mailto:[email protected]>>
>>> wrote:
>>> 
>>> I'd always just assumed that Arithmetic was chosen so that
>>> SignedArithmetic wouldn't clash with the old SignedNumber. If
>>> that's not an issue, definitely agree that Number is the superior
>>> name.
>>> On Fri, Jan 27, 2017 at 08:30 T.J. Usiyan via swift-evolution
>>> <[email protected] <mailto:[email protected]>>
>>> wrote:
>>> Oh, I misread the arrows in that diagram and this makes much more sense now.
>>> 
>>> Thanks.
>>> 
>>> On Fri, Jan 27, 2017 at 9:14 AM, Stephen Canon <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> The bitwise stuff isn't on ArithMETic | ARITHmetic | Number | whatever.
>>> 
>>>> On Jan 27, 2017, at 9:13 AM, T.J. Usiyan via swift-evolution
>>>> <[email protected] <mailto:[email protected]>>
>>>> wrote:
>>>> 
>>>> Regarding `Number` or `Numeric`: Does everything in Arithmetic
>>>> apply to complex numbers and do we want it to? The bitwise stuff
>>>> is where I think that there might be a mismatch.
>>>> 
>>>> On Thu, Jan 26, 2017 at 2:26 PM, Dave Abrahams via swift-evolution
>>>> <[email protected] <mailto:[email protected]>>
>>>> wrote:
>>>> 
>>>> on Sun Jan 15 2017, Stephen Canon <[email protected] 
>>>> <mailto:[email protected]>> wrote:
>>>> 
>>>> > Responding to the thread in general here, not so much any specific email:
>>>> >
>>>> > “Arithmetic” at present is not a mathematically-precise concept, and
>>>> > it may be a mistake to make it be one[1]; it’s a
>>>> > mathematically-slightly-fuzzy “number” protocol.
>>>> 
>>>> 
>>>> In that case, should we consider renaming it to “Numeric” or even
>>>> “Number?”  That would at least remove the question about how to
>>>> pronounce it.
>>>> 
>>>> 
>>>> --
>>>> -Dave
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> [email protected] <mailto:[email protected]>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution 
>>>> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> [email protected] <mailto:[email protected]>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution 
>>>> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> [email protected] <mailto:[email protected]>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> [email protected] <mailto:[email protected]>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected]
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>

-- 
-Dave
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to