Substrate

#protocols #generics
Protocols III: Existential Spelling
Protocols III: Existential Spelling
Existentials and universals are [logical] “duals,” which means that one can be transformed into the other without losing its structure. So `AnySequence` is a universal type (generic) that’s equivalent to an explicit existential of `Sequence` (protocol). That’s why when you run into problems with protocols, your solution may be to convert it into generic structs (or vice versa). They solve the same problems in different ways with different trade-offs. And when you see “can only be used as a generic constraint,” what the compiler is really telling you is that protocols with associated types (PATs) don’t have an existential.
·robnapier.net·
Protocols III: Existential Spelling
Improving the UI of generics
Improving the UI of generics
We could think of type-level-abstracted return types as doing the same thing but at the type level; you give a function generic arguments as inputs, and it gives a certain return type back. ​ This roughly follows the progression of `impl Trait` in Rust, where it was first introduced only for return types, then was generalized to be able to appear structurally in both argument and return types. We think this is a reasonable first step because it directly addresses the biggest functionality gap in the generics model. After that first step, there are a few fairly orthogonal language change discussions we can have, some of which are already underway
·forums.swift.org·
Improving the UI of generics