SE-0244: Opaque Result Types

What is your evaluation of the proposal?

I think it's good. My two gripes with it are:

  • I'd rather have opaque as the keyword for this feature. It's not that I worry much about the ambiguity with Optional.some, but I'd rather see the feature name aligned with what you see in the source code.

  • I worry about the inability to refer in other code. If you can't name it, it's difficult to store as a variable in a struct or elsewhere, and it's difficult to write wrapper functions without each of them creating a new distinct opaque type.

Is the problem being addressed significant enough to warrant a change to Swift?

I think the feature will be useful enough once further developed. I'm not too sure of the utility without the ability to add constraints to the opaque type. Sure, you can shuffle the elements in an opaque collection, but if you can't read any of them, what's the point?

Does this proposal fit well with the feel and direction of Swift?

I think it will, mostly, once we have constraints. My main reserve is about the various consequences on composability introduced by having anonymous types. The main problem is the difficulty of giving them a name.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

It feels a bit like opaque pointers in C, commonly used to hide implementation details. But instead of exposing global functions taking an opaque pointer, you expose methods in a protocol.

Opaque types are quite similar to Voldemort types in D. But in D you can still declare a variable of a type that cannot be named using typeof(<some_expression>) so it does not really affect composability.

One common issue with Voldemort types in D is the excessive growth in mangled function names the can happen when combined with templates. I'm not too sure if this applies to Swift or not since the proposal has little to say about name mangling, but I find it likely that generic function specialization that would include specialization of their opaque type could result in similar issues.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Participated in the pitch, but mostly skimmed the actual review thread.

1 Like