[swift-evolution] Make generics covariant and add generics to protocols

Howard Lovatt howard.lovatt at gmail.com
Wed Jan 13 16:03:16 CST 2016


@Thorsten,

It doesn't make the type system unsound; the types are mostly checked at
compile time but some are runtime checked, either way the types are checked
and therefore the type system is sound. I have posted an example of array
runtime type checking in a previous response.

You can annotate variance, but this generally adds a lot of clutter to the
code (see some typical Java code that uses generics you will see stuff like
? extends Type everywhere). In other languages like Scala the annotation is
less visually intrusive, because they use shorter syntax and because it is
annotated at declaration site rather than use site, but it is still there.

I think Swift arrays are a good example of partially static and partially
runtime checked. The content is statically typed but the size is runtime
typed. Other languages do type both the content and the size (see Dependent
Typing on Wiki), however at some considerable burden on the programmer.

Hope this explains the thought process,

 -- Howard.

On 13 January 2016 at 16:50, Thorsten Seitz <tseitz42 at icloud.com> wrote:

> Strong -1 from me as well for making the type system unsound.
>
> > Am 13.01.2016 um 02:47 schrieb Howard Lovatt via swift-evolution <
> swift-evolution at swift.org>:
> >
> > Yes you can annotate for covariance, invariance, and contravariance,
> both Java and Scala, allow all three. The problem is that the code becomes
> splattered with variance annotations
>
> Ceylon uses a different approach which is variance annotations at the
> definition site.
> This restricts the possible usage of the type parameters to appropriately
> variant positions.
>
> This migt be a better way to deal with variance.
>
> -Thorsten




-- 
  -- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160114/5031ea36/attachment.html>


More information about the swift-evolution mailing list