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 _______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users