[swift-evolution] Pre-proposal: Safer Decimal Calculations

Tino Heth 2th at gmx.de
Sat Mar 19 07:03:45 CDT 2016


> Just wanted to expand on the type tolerances idea with an example:
> 
> 	let a:Float±0.1 = 1234.56
> 	let b:Float±0.5 = 123.456
> 
> 	let result:Float±0.25 = a + b // Error as b’s tolerance > 0.25
That example is a good motivation for two things I would like to see in Swift:
- Generic value parameters (has been proposed, but lacks traction)
- Inheritance for structs / "newtype"-feature (should have been proposed weeks ago…)

With both things available, it would be possible to implement your example with a slightly different syntax:
let a: FloatNumber<tolerance: 0.1> = 1234.56

Better support for plain simple calculations would be really cool — I still remember how impressed I've been the first time I saw the Scheme-Interpreter printing a number that filled the whole screen ;-)

Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160319/381c4688/attachment.html>


More information about the swift-evolution mailing list