News for hackers. Stuff that matters.
Re:Swift Evolution acceptances: The big three by zoul on Friday March 04, 2016 @07:44AM (#11223370)
Would you have an example for someone who doesn’t know anything about higher-kinded types?
Re:Swift Evolution acceptances: The big three by cballard on Friday March 04, 2016 @09:53AM (#11224063)
Both 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).