[swift-evolution] Support for newtype feature/typesafe calculations

Tino Heth 2th at gmx.de
Thu Jan 7 08:41:41 CST 2016

> that much unit safety with numbers. But when I read "epic typesafe calculations", that's what I think about.
me to ;-) — and I want this to work with force vectors, matrices and tensors as well.
But I'm quite sure that composed units are the hardest part, and I don't think it will be possible in Swift 3.

I would like to start with tiny steps, and afaics, we miss a protocol that denotes that something can be added and substracted, don't we?

So, I think a first tiny proposal would be to add protocols for groups, rings & bodys, and add make the numeric types conform to them.

Meanwhile, I pushed a tiny playground to github - it is quite chaotic, but it allows you to do stuff like
let f0 = Force.Newton(1)
let f1 = Force.Kilopound(1)
print(10.0*f0 + f1/444.8221615255)

https://github.com/SwiftTypesafeCalculations/Units <https://github.com/SwiftTypesafeCalculations/Units>

I did also start an "organization" at github and to see how this infrastructure can be leveraged to channel the discussion without loosing track.

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

More information about the swift-evolution mailing list