[swift-evolution] Epic: Typesafe calculations
Tino Heth
2th at gmx.de
Tue Dec 29 08:52:29 CST 2015
> Yes, care needs to be taken about the associativity and commutativity of multiplication of units, but that's not too hard either, it basically amounts to some pattern matching along with symbolic computations respecting algebraic identities (think of it as a compile-time "unit interpreter") and maybe some post-normalization.
I agree: "doing it right" is no rocket science (pun intended ;-) — but I'm quite sure it won't be possible unless the macro-system that might be introduced with Swift 4 is ready.
But there are possible workarounds for the lack metaprogramming the type system, so products with three or four factors should be possible without even changing the compiler (it will be ugly, though):
It is easy to define +/- for composed units, but it is a huge amount of code that has to be generated for all permutations.
@Tim Hawkins:
Thanks for posting the link — although it reminds me on feeling bad for not being in Hamburg right now ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151229/b367d7c7/attachment.html>
More information about the swift-evolution
mailing list