Explicit type annotation to support discoverability between bridging / implicitly convertable types

Preamble

I would like to start a discussion round which may or may not be picked up by someone and result in a formal proposal. I will not have enough spare time to move along or push this discussion, but I wanted to start it just for the record on the forums so the idea won't be lost.

It would be great if the language would provide an exhaustive list / type relation for types that can be implicitly converted / bridged into other types, similar to type inheritance or protocol conformance.

These types might require an explicit flag / attribute as the language may still not support some feature set (like existentials with a where clause) to naturally support the conversion (e.g. AnyHashable). However an implicit flag does not fit every scenario. As previously mentioned, we can wrap a Hashable type implicitly into a AnyHashable, therefore it's impossible to statically provide a list of all types what can be wrapped into AnyHashable, nor is it goal to annotate every hashable type to make this conversion discoverable. That said, I think that automatic wrapping for existential like types with compiler support would require a different solution or we just keep them as is.

The TL;DR is that a language user would benefit from a discoverable type relation between types that can be bridged / implicitly converted into one or both directions, types like in recent CGFloat <-> Double proposal, UIFont -> CTFont, etc.


5 Likes

I wonder whether the same technique being pitched here is just as applicable in this case, too.