interfaces and contracts - new pattern

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Dec 3 15:26:10 UTC 2019


On Tuesday, 3 December 2019 at 15:12:46 UTC, Ola Fosheim Grøstad 
wrote:
> On Tuesday, 3 December 2019 at 14:51:58 UTC, Adam D. Ruppe 
> wrote:
>> Maybe, but it is pretty sound once you get to know it.
>
> You mean contracts? Yes. But I was thinking of 
> contravariant/covariant parameters on virtual functions. 
> Doesn't work with overloading though, so D only has it on 
> return types? Probably for the best. Perhaps.

Also the use of the term "covariant" here is confusing to me:

https://dlang.org/spec/function.html

My understanding is that covariant means that an enclosing type 
and the enclosed type have the same typing-relationship when 
specialized. Whereas contravariant means they are opposite. So 
you need two types for it to make sense. I.e. the schematic here:

https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Inheritance_in_object-oriented_languages

But it the documentation "covariant" is used to describe a simple 
subtyping-relationship on one type?

Anyway, the wording is confusing. I think it would be hard on 
newbies, even if it was correctly used.



More information about the Digitalmars-d-announce mailing list