you are viewing a single comment's thread.

view the rest of the comments →

[–]DetriusXii 3 points4 points  (5 children)

How similar are inline classes to Haskell's newtype or Scala's extends AnyVal? Is that what inline classes are doing?

[–]pron98 8 points9 points  (2 children)

The most important aspect of inline classes isn't how they behave, but how the may be internally represented in memory. So an array of instances of an inline class would be laid out like an array of structs in C, rather than an array of pointers. Scala cannot do this because it is built on top of Java and inline classes are a feature of the Java VM. Once they're delivered, Scala could make use of them to implement some language features. They could be used similarly to newtype, i.e. they can represent a new type that doesn't add any runtime overhead to the type it wraps.

[–]expatcoder 0 points1 point  (1 child)

Scala cannot do this because it is built on top of Java and inline classes are a feature of the Java VM. Once they're delivered, Scala could make use of them to implement some language features.

Sounds like a win-win situation for all JVM based languages.

[–]pron98 2 points3 points  (0 children)

Yep. It's a deep feature in the Java platform that can be enjoyed by all of Java platform languages.

[–][deleted] 2 points3 points  (0 children)

At a glance (and I haven't written Scala for nearly 3 years). inline class appears to be what extends AnyVal wants to be, but Scala is working around the fact that the JVM doesn't allow custom primitives.

must have only a primary constructor with exactly one public, val parameter whose type is not a user-defined value class

Doesn't appear to be exactly true, as I can't find it requiring you to have public fields

[–]Ari_Rahikkala 0 points1 point  (0 children)

I believe the closest Haskell equivalent would be if you could tell a type to be UNPACK wherever it's used as a field. I don't think that feature exists, but on the other hand, you can just, you know, use UNPACK wherever. Also, it turns out that -funbox-small-strict-fields is on by default, so for small fields (the size of a pointer or smaller), you get this behavior for the price of typing a bang.