[swift-users] Implementing signum
Dave Abrahams
dabrahams at apple.com
Mon Nov 28 20:46:53 CST 2016
on Sun Nov 20 2016, Hooman Mehr <swift-users-AT-swift.org> wrote:
> Let me explain this a bit further:
>
> Swift generic programming is very different from C++ template
> programming. Swift compiler needs to type-check generic code on spot,
> not while instantiating the template (because in Swift, instantiation
> can occur at runtime if the generic code is from a different module).
To be clear, that's true, but it's not the reason we typecheck generic
code at its point-of-definition. The fact that instantiation can occur
at runtime is almost completely an artifact of our implementation model,
rather than a part of how the language is defined.
We typecheck generics at the point of definition because it's the right
thing to do, regardless of your implementation model. The alternative
leaves you writing generic code that appears to compile but actually
only works for the one or two cases you tested it with, and that
generates the infamous C++ “template instantiation backtrace” when it
fails.
--
-Dave
More information about the swift-users
mailing list