Empty value types
Gavin Bierman
gavin.bierman at oracle.com
Sun Aug 10 08:18:04 UTC 2014
Greetings from Northern Australia! Just saw this - this is a well known pattern in functional programming called phantom types (due to our friend Erik Meijer)
Gavin
Sent from my iPhone
> On 2 Aug 2014, at 02:35, Paul Govereau <paul.govereau at oracle.com> wrote:
>
> I don't think there is anything wrong with it. I can even think of a use case: phantom types.
>
> final __ByValue class ReadWrite {}
> final __ByValue class ReadOnly {}
> final __ByValue class File<T> { ... }
>
> File<ReadWrite> openForWrite(String file) { ... }
> File<ReadOnly> openForRead(String file) { ... }
>
> void write(File<ReadWrite> file, ...) { ... }
>
> However, I think we need to add checks to detect construction of empty value types. I am not sure what to do about methods defined inside of an empty type? Maybe only static methods are OK?
>
> Paul
>
>> On 08/01/2014 12:50 PM, Brian Goetz wrote:
>> While an empty value is silly, is there something actually wrong with it?
>>
>> Sent from my iPhone
>>
>>> On Aug 1, 2014, at 9:47 AM, Paul Govereau <paul.govereau at oracle.com> wrote:
>>>
>>> What are we going to do with empty value types?
>>>
>>> The most sensible thing seems to allow them to be declared but not constructed. e.g.
>>>
>>> final __ByValue class Void {} // <- ok
>>>
>>> Void v = __Make Void(); // <- error cannot construct empty type.
>>>
>>> Paul
More information about the valhalla-dev
mailing list