Feedback on Sealed Types

John Rose john.r.rose at oracle.com
Thu May 2 02:42:08 UTC 2019


On May 1, 2019, at 5:32 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> 
> If there is only one constant of type Empty and the construction is typesafe, it can be a huge win.

If Empty is an inline (value) type with no components,
then Empty.default is the singleton, and there's nothing
else to say about it.  This is a use case for empty inlines.
In fact they are unit types, as recognized in many languages.

(There are some low-level technical reasons why Valhalla
doesn't support this now, but they can be overcome with a bit
of work.  One problem is how to keep track of a field of size
zero, if you are using relative offsets at present.)

— John

P.S.  Either a sum of N zero-length unit types or a classic
enum of N elements, could be represented as a byte of lgN bits.
(Or lg(N+1) if it's nullable.)  We can't do this in the old contract
of L-types, but under the new contract that allows early loading
of field types, we could pull such tricks for either enums or
unit-sums, in the JVM.  So if Foo is a small enum, LFoo; requires
8 or 4 bytes, but GFoo; (where G is the "go and look" contract)
can require just 1 byte, just like a boolean.



More information about the amber-spec-experts mailing list