3 ms·
Big things missing from Swift IMO: - Higher-kinded types - Strictly-typed "throw" I'm not sure about dropping "Type" from protocols because it's pretty commo
by cballard 11y ago
Big things missing from Swift IMO:
- Higher-kinded types
- Strictly-typed "throw"
I'm not sure about dropping "Type" from protocols because it's pretty commonly used to separate the protocol definition (which is extended to provide most of the implementation) from the concrete base implementation, e.g. RAC's SignalProducerType/SignalProducer.
- whateveracct 11y agoSwift protocols are begging for HKTs.
- zoul 11y agoWould you have an example for someone who doesn’t know anything about higher-kinded types?
- cballard 11y agoBoth Optional and Array have flatMap, i.e. T?.flatMap(T -> R?) -> R? [T].flatMap(T -> [R]) -> [R] However, you cannot write a protocol for "things that can be flatMapped", because you cannot refer to a Self<T> specialized with a different type (Self<R>). With HKTs, you can do that, which would let you write something like this: protocol FlatMappable { typealias Value func flatMap<R>(Value -> Self<where Value == R>) -> Self<where Value == R> } That's not useful on its own, but it means that you can now write functions and extensions that reason about the general concept of anything FlatMappable (this is most of the way to what is known as monads, FWIW).