[swift-evolution] [swift-evolution-announce] [Review] SE-0048: Generic Type Aliases

T.J. Usiyan griotspeak at gmail.com
Tue Mar 29 16:40:43 CDT 2016


This feature removes the need, in specific cases, for wrapping a function
in a struct 'just for' the ability to use generics.

```swift
typealias Parser<Output> = String -> Output

// can now, sometimes, replace

struct Parser<Output> {
    let transform: String -> Output
    init(transform: String -> Output) {
        self.transform = transform
    }
```

Both are useful but being forced to use the second declaration when the
first would suffice is frustrating.



On Tue, Mar 29, 2016 at 7:14 PM, Dave Abrahams via swift-evolution <
swift-evolution at swift.org> wrote:

>
> on Mon Mar 28 2016, Chris Lattner <clattner-AT-apple.com> wrote:
>
> > On Mar 24, 2016, at 1:18 PM, Dave Abrahams via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>>
> >>> Is the problem being addressed significant enough to warrant a change
> >>> to Swift?
> >>
> >> That's my biggest question about this proposal.  Yes, as the proposal
> >> says, generic type aliases fill an obvious functional gap.  But what
> >> real-world problems are they solving
> >
> > They allow you to make aliases for generic types, e.g. from the document:
> >
> >       typealias StringDictionary<T> = Dictionary<String, T>
> >       typealias DictionaryOfStrings<T : Hashable> = Dictionary<T, String>
> >       typealias IntFunction<T> = (T) -> Int
> >       typealias Vec3<T> = (T, T, T)
> >       typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
>
> I know what the feature allows.  What I don't see is any burning need
> for it.
>
> > It is an inconsistency in the language that you can create aliases for
> > non-generic types, but that you can’t make them for generic ones.
> > Perhaps you are objecting to typealias as a feature at all?
>
> I'm not objecting at all.  It's an obvious thing for us to do, and we
> should do it at some point.  It just doesn't seem very impactful or
> crucial.
>
> >> and why should adding them be a priority?
> >
> > It is part of the general goal of completing the generics system, a
> > stated Swift 3 goal.
>
> True.  I just wonder if we should be frying bigger fish.
>
> --
> Dave
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160329/3d2837d4/attachment.html>


More information about the swift-evolution mailing list