[swift-evolution] Expanded support for numeric types in stdlib?

Kevin Ballard kevin at sb.org
Fri Dec 4 01:21:22 CST 2015


On Dec 3, 2015, at 9:48 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
>> A good invariant for Rationals might be having them always
>> represented in the most simplified form - for example, Rational(2, 6) should
>> be represented internally as 1/3 when constructed.
> 
> This has performance tradeoffs.  What do other libraries and languages do?

I know Haskell always reduces Rationals to their reduced form. This does have performance implications, but not doing so has surprising consequences for operations you perform on them. For example, it’s reasonable to expect that Rational(2,6) == Rational(1,3), but implementing that without reduced Rationals pretty much requires reducing them on the fly. The alternative, of saying they’re not equal, would probably surprise most people.

-Kevin Ballard


More information about the swift-evolution mailing list