Live data from Hacker News

Type Erasure Magic in Swift

realm.io

1–10 of 10 posts

Re: Type Erasure Magic in Swift

#2
As a TL;DR, or even as a starting point for diving deeper into the finer points in the talk, it would be really helpful to attach the complete code which demonstrates type erasure.

Re: Type Erasure Magic in Swift

#6
post #5

Why do all sorts of blogs have "Click to Read More" buttons these days? Seems totally unnecessary.

It makes the adverts stand out more, and that pays the bills.

Edit: it seems the old location for adverts, the sidebar, is dead because people zoom in on mobile and many users are on mobile.

Pop-ups also are somewhat dead because people have learned to close the not-too obnoxious ones without paying attention.

Re: Type Erasure Magic in Swift

#7
post #3
post #2

As a TL;DR, or even as a starting point for diving deeper into the finer points in the talk, it would be really helpful to attach the complete code which demonstrates type erasure.

Agreed. Although, the code is in the presentation.

It might be in the video (I don't have time to watch it to find out). It isn't in the slides (which I can skim quickly, and therefore I did).

Re: Type Erasure Magic in Swift

#8
> In Java it is used to let the compiler know and it will erase the and make it a concrete type.

It's the opposite. In Java, when you instantiate a generic class with a concrete type, it will erase that type in the generic class. So, the actual code for Foo and Foo is the same; String and Integer are erased, and inside of Foo, it just uses Object. For that reason, Foo is not allowed to do anything with T that would require knowing the actual type of T; that knowledge has been erased. See https://docs.oracle.com/javase/tutorial/java/generics/erasur...

With this confusion, it's hard for me to orient myself with how this applies to Swift.

Re: Type Erasure Magic in Swift

#9
This seems like an apology for the unforgivable: type erasure is a language implementation detail, and thus it shouldn't affect language users. A user might want to choose an implementation that uses monomorphization for performance reasons, or an implementation that doesn't erase types for debuggability reasons. But the language implementor's choice to use type erasure shouldn't affect the meaning of code written by language users.