Hi Christian,

On Fri, Sep 29, 2023 at 10:30 AM Christian Brabandt <
[email protected]> wrote:

> what is contr-variant?
>
>
> Consider the following example (from #12965):

class A
endclass

class B extends A
endclass

class C extends B
endclass

In this example, type "C" is a covariant of type "B" and "A" is
contra-variant of type "B".

This matters when overruling methods in an extended class.  The method
return value
type in an extended class can use a covariant type of return value in the
parent class.
The type of method arguments in an extended class can use a contra-variant
type.

For example (continuing the above example):

class Foo
  def Doit(p: B): B
    return B.new()
  enddef
endclass

class Baz extends Foo
  def Doit(p: A): C
    return C.new()
  enddef
endclass

The Doit() method in class Foo uses "B" as the argument type and "B" as the
return type.
The Doit() method in class Baz uses "A" as the argument type and "C" as the
return type.
"A" is a contra-variant of "B" and "C" is a co-variant of "B".

A detailed explanation about this is in
https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
.

I wanted to follow the model used in the Dart language (
https://medium.com/dartlang/dart-declaration-site-variance-5c0e9c5f18a5).

Regards,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7mTBy9PecxrxazoT4dDZFX9au9AiiFDso4t5Zceg5Xt%2BA%40mail.gmail.com.

Raspunde prin e-mail lui