[swift-users] scientific library for swift?

Tino Heth 2th at gmx.de
Wed Dec 23 10:52:19 CST 2015


> Please NO. Templates are the worst idea ever to evolve from C++. Never let this madness enter into Swift, it has done enough damage in the C++ world already.
Hey, templates are cool — they are even Turing complete! ;-)
No, I really don't think it's that useful to calculate Fibunacci-numbers at compile time (at least I don't think C++ template syntax is a good tool to do so).

But it wouldn't be that hard to implement something in between generics and full template support, without the dangers (that's what I meant with "limited").
I might write a proposal some day, but the concept isn't that hard:
Right now, we can have something like
let m = Matrix(rows: 3, columns: 4)
easily.
There's just the problem that the compiler cannot deduce which matrices are "compatible", as there is only one Matrix-type.
If we had a way to tell the compiler that "rows" and "columns" have an effect on the type, everything would be fine, and this model of compile-time parameters imho is quite simple:

struct FloatVector<dimensions: UInt> {
	private var elements = Array<Float>(capacity: dimensions)
…
}

let vector = FloatVector<3>(0, 0, 1)
let otherVector = FloatVector<2>(0, 1)

let sum = vector + otherVector // compiler error, type mismatch

I think many problems with template happen because they are not compiled unless you use them, and compile-time parameters wouldn't suffer from this.

Best regards,
Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151223/e09efe8e/attachment.html>


More information about the swift-users mailing list