[swift-evolution] [Design Question] Metaprogramming as a non-goal
Thorsten Seitz
tseitz42 at icloud.com
Sun Jan 24 03:04:49 CST 2016
Unfortunately that’s exactly what would make a library with typed units possible (see thread about „Epic: Typesafe calculations“).
-Thorsten
> Am 24.01.2016 um 10:01 schrieb Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org>:
>
> I'd guess the point is that the generics system isn't meant to force the compiler to perform the sorts of things C++'s (Turing-complete) template system can:
>
> template<size_t... F>
> struct Fibonacci { };
>
> // API
> template<size_t n>
> struct Fibonacci<n> {
> static constexpr size_t value = Fibonacci<n, 1, 0>::value;
> };
>
> // Recursive implementation
> template<size_t n, size_t Fn, size_t Fm>
> struct Fibonacci<n, Fn, Fm> {
> static constexpr size_t value = Fibonacci<n-1, Fn+Fm, Fn>::value;
> };
>
> // Base case
> template<size_t Fn, size_t Fm>
> struct Fibonacci<0, Fn, Fm> {
> static constexpr size_t value = Fn;
> };
>
> int main() {
> printf("F(200): %zu\n", Fibonacci<200>::value);
> return 0;
> }
>
> Jacob
>
> On Sat, Jan 23, 2016 at 11:17 PM, Michael Henson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> In the swift/docs/Generics.rst documentation, I see:
>
> "
> As important as the goals of a feature are the explicit non-goals, which we don't want
> or don't need to support:
> * Compile-time "metaprogramming" in any form
> * Expression-template tricks a la Boost.Spirit, POOMA
> "
>
> What kinds of things count as compile-time metaprogramming? I've been tinkering with some ideas related to the type system and having a more specific description here might help me pare many / most / all of them down.
>
> Mike
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160124/914af74e/attachment.html>
More information about the swift-evolution
mailing list