[swift-evolution] I think we need more to our type calculus

Daryle Walker darylew at mac.com
Wed Feb 8 14:09:30 CST 2017

I’ve been trying to get the maximum of a list of counts. I started by using “myCollection.map { $0.myCountProperty }.reduce(0, max)”. Then I thought I should really use the value closest to negative infinity as the base. The problem is how to get that value. The current hard-coded “0” works because the count type ultimately aliases “Int”, but shouldn’t have to count on that. I put in “MyCountType.min”, where “MyCountType” is hard coded from the docs of “myCountProperty”, but I shouldn’t have to do that either.

There is a “type(of:)” global function, which I did use. But not only did I have to make up an expression to go in there, its return value, some sort of meta-type stuff I don’t understand, can’t be used on the right side of a “typealias” construct. I ultimately used “let lowestCount = type(of: anElement.myCountProperty).min” to get what I needed.

Some queries/requests:

1. Is the expression within “type(of:)” evaluated?
2. I think we need the equivalent of "std::declval” from C++. Especially if the answer to (1) is yes.
3. Why isn’t the return type(?) of “type(of:)” compile-time enough to be used as a type-alias?
4. Should we add something like the C++ type-traits collection of generic structures to give use type information as type-aliases or type-level instances?

Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170208/57c7b4cf/attachment.html>

More information about the swift-evolution mailing list