DIP 1017--Add Bottom Type--Final Review
Neia Neutuladh
neia at ikeran.org
Tue Jan 22 18:34:08 UTC 2019
On Tue, 22 Jan 2019 16:52:12 +0000, Olivier FAURE wrote:
> On Tuesday, 22 January 2019 at 16:09:39 UTC, Neia Neutuladh wrote:
>> Because it makes field order significant. It means that these two types
>> are different:
>>
>> struct A { int x; string y; }
>> struct B { string y; int x; }
>
> I think that's a fair distinction to make.
>
> Except for the most hardcore "virtualize every member" type system
> implementations, most languages will require a non-trivial amount of
> operations (as many as there are fields) to get an A from a B and
> vice-versa, whereas prefix casting is essentially free.
In a structural type system, functions take "anything that conforms to this
interface" and return "something that conforms to this interface".
The Go-style implementation is to separate interfaces from normal types and
for the compiler to create adapters left and right. This is what you seem
to be thinking of.
The Haskell-style implementation (if I recall correctly) is to implicitly
convert a function involving an interface into a template function. This
has some implications for covariance and contravariance that functional
languages tend to sidestep using immutability.
More information about the Digitalmars-d
mailing list