News for hackers. Stuff that matters.
Re:Static Types in SwiftUI by layoutIfNeeded on Tuesday November 05, 2019 @05:07PM (#21457267)
Yep. The funny thing is that if you try to use this new automatic type-erasure stuff for anything but SwiftUI, you will soon encounter compiler errors like “`some` types are only implemented for method return types or computed property accessor return types”. Lol.

So e.g. you can’t use `some`-typed variables or stored properties.

Re:Static Types in SwiftUI by NobodyNada on Tuesday November 05, 2019 @05:48PM (#21457621)
The `some` keyword declares an opaque result type ([0]), which means "this function has a concrete return type, but the identity of that type is a hidden implementation detail." An opaque result type can be used like a generic type -- the compiler doesn't know the exact type, but it does know that calls to the function will always return the same type (which is important when working with protocols such as `Equatable` that have associatedtype or Self requirements).

A `some`-typed variable or stored property wouldn't make any sense because it would be a variable that has a concrete but unknown type. You can't assign something to such a variable, because there's no way to know whether the value you're trying to assign matches the hidden concrete type of the variable.

Perhaps the "automatic type-erasure" feature you're wanting is actually generalized existentials ([1])? Generalized existentials would allow you to declare a variable whose type can be "any Equatable", rather than "some (specific but unknown) Equatable", and the compiler would allow you to "open" the existential and use it like a generic type (without throwing the "protocol can only be used as a generic constraint because it has Self or associatedtype requirements" error).

[0]: https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.... [1]: https://github.com/apple/swift/blob/master/docs/GenericsMani...

Re:Static Types in SwiftUI by favorited on Tuesday November 05, 2019 @07:17PM (#21458439)
You definitely can have a 'some' type property[0]. Computed properties work just like functions do. Stored properties just need a value assigned, like so:

    let strings: some Collection = ["hello", "world"]
[0]https://github.com/apple/swift-evolution/blob/master/proposa...