[Pitch] Self.withoutSpecialization


(TJ Usiyan) #1

## The Issue
Given

public protocol Zipper1D : CustomStringConvertible {
    associatedtype Element
}

We can almost write a `flatMap` which keeps the general identity of self
and swaps out the Element in the output.

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
>

        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

## The Proposal
I propose that we allow `Type.withoutSpecialization`

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
NewElement, Output.withoutSpecialization == Self.withoutSepcialization>
        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

I recognize that generic protocols are another possible solution to this
problem. I am pitching this because of how much closer this idea seems to
being realized.


(TJ Usiyan) #2

Bump

···

On Fri, Jul 1, 2016 at 11:56 AM, T.J. Usiyan <griotspeak@gmail.com> wrote:

## The Issue
Given

public protocol Zipper1D : CustomStringConvertible {
    associatedtype Element
}

We can almost write a `flatMap` which keeps the general identity of self
and swaps out the Element in the output.

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
>
        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

## The Proposal
I propose that we allow `Type.withoutSpecialization`

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
NewElement, Output.withoutSpecialization == Self.withoutSepcialization>
        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

I recognize that generic protocols are another possible solution to this
problem. I am pitching this because of how much closer this idea seems to
being realized.


(Dave Abrahams) #3

The right answer to this problem is something called “higher-kinded
types,” which are interesting to contemplate for the future, but most
definitely out-of-scope at the moment.

Cheers,

···

on Fri Jul 01 2016, "T.J. Usiyan via swift-evolution" <swift-evolution@swift.org> wrote:

Bump

On Fri, Jul 1, 2016 at 11:56 AM, T.J. Usiyan > <griotspeak@gmail.com> wrote:

## The Issue
Given

public protocol Zipper1D : CustomStringConvertible {
    associatedtype Element
}

We can almost write a `flatMap` which keeps the general identity of self
and swaps out the Element in the output.

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
>
        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

## The Proposal
I propose that we allow `Type.withoutSpecialization`

func flatMap<
        NewElement, SegmentOfResult : Collection, Output : Zipper1D where
        SegmentOfResult.Iterator.Element == NewElement, Output.Element ==
NewElement, Output.withoutSpecialization == Self.withoutSepcialization>
        (_ transform: @noescape (Element) throws -> SegmentOfResult)
rethrows -> Output

I recognize that generic protocols are another possible solution to this
problem. I am pitching this because of how much closer this idea seems to
being realized.

--
-Dave


(TJ Usiyan) #4

I periodically kill all hope that we might get higher-kinded-types, just to
remain sane.

It's interesting that you would make them sound like a possibility though,
since Mr Widmann said something about you declaring them intractable for
some reason or another.

Well, this attempt to get them by hook or crook failed, but I won't let
that get me down. No. No I won't.

···

On Sat, Jul 2, 2016 at 11:40 AM, Dave Abrahams via swift-evolution < swift-evolution@swift.org> wrote:

on Fri Jul 01 2016, "T.J. Usiyan via swift-evolution" < > swift-evolution@swift.org> wrote:

> Bump
>
> On Fri, Jul 1, 2016 at 11:56 AM, T.J. Usiyan > > <griotspeak@gmail.com> wrote:
>
>>
>>
>> ## The Issue
>> Given
>> ``` swift
>> public protocol Zipper1D : CustomStringConvertible {
>> associatedtype Element
>> }
>> ```
>>
>> We can almost write a `flatMap` which keeps the general identity of
self
>> and swaps out the Element in the output.
>>
>> ``` swift
>> func flatMap<
>> NewElement, SegmentOfResult : Collection, Output : Zipper1D
where
>> SegmentOfResult.Iterator.Element == NewElement, Output.Element

>> >
>> (_ transform: @noescape (Element) throws -> SegmentOfResult)
>> rethrows -> Output
>> ```
>>
>> ## The Proposal
>> I propose that we allow `Type.withoutSpecialization`
>>
>> ``` swift
>> func flatMap<
>> NewElement, SegmentOfResult : Collection, Output : Zipper1D
where
>> SegmentOfResult.Iterator.Element == NewElement, Output.Element

>> NewElement, Output.withoutSpecialization == Self.withoutSepcialization>
>> (_ transform: @noescape (Element) throws -> SegmentOfResult)
>> rethrows -> Output
>> ```
>>
>>
>> I recognize that generic protocols are another possible solution to this
>> problem. I am pitching this because of how much closer this idea seems
to
>> being realized.

The right answer to this problem is something called “higher-kinded
types,” which are interesting to contemplate for the future, but most
definitely out-of-scope at the moment.

Cheers,

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution