[swift-evolution] Epic: Typesafe calculations

Tino Heth 2th at gmx.de
Wed Jan 13 05:50:20 CST 2016


Hello Matt!

> Hi Tino, Thanks for making your proposal.
well, it has to be decided yet if that document turns into a real proposal (but I hope so ;-)  

> got me thinking.  What if parameters marked with static, or constexpr, or some such, could complement template parameters, rather than being an alternative to them.  Basically, stuff between the angle brackets is relevant for determining storage needed, and other constexpr parameters enable arbitrary compile time checks.  I hope the mailing list doesn’t mind a little brainstorming about these further off features.
imho the list is quite good at simply ignoring stuff it doesn't care for :-) — but I would expect some feedback if you open a thread for the topic:
I'm still waiting for someone asking for compile-time execution with a reference to 
https://www.youtube.com/watch?v=UTqZNujQOlA <https://www.youtube.com/watch?v=UTqZNujQOlA>
(it's such a cool concept — we really should have a use case for it :), and your idea is a variant of this feature.

I have read several times that Swift 3 won't have macros, but have the impression that this is a huge topic, so even if proposals heading in this direction won't (most likely) be accepted now, they might become important next year.
As far as I know, some compilers are already clever enough to replace simple calculations (like secondsPerDay = 60*60*24; f = pi * 2.0;…), so it is not that strange to extend that concept.
In theory, this could work without new keywords (when all input is known at compile time, just evaluate), but as speed at runtime isn't always the most important aspect, some sort of hint might be better.

I'm sure that checks at compile-time would not only be useful for calculations:
NSURL, for example, can be initialized with a string that simply does not represent an URL (therefore, init can return nil). But if the parameter is a string literal, you'll always have the same result at runtime…

Best regards,
Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160113/7fdf5c1b/attachment.html>


More information about the swift-evolution mailing list