Questions tagged [covariant]

Type constructors in programming languages which preserve subtype relations

This tag regards a feature of type-constructors in programming languages: syntactic constructs which are applied to types to produce other types. Example of type constructors: An array of elements of the original type, a pointer to the original type etc.

A unary type constructor tc is covariant if applying tc preserves the subtype relationship of types. That is, if B is a subtype of A, then tc applied to B is a subtype of tc applied to A.

If the subtype relationship is inverted rather than preserved, the type constructor is .

Further reading (Wikipedia).

72 questions
1
vote
1 answer

C++ class design: Covariance

The Problem I want to implement a number of algorithms that work on a graph and return scores for node-pairs indicating whether those nodes are similar. The algorithms should work on a single node-pair and on all possible node-pairs. In the latter…
xZA
  • 153
  • 1
  • 7
1
vote
1 answer

Academic: Automatic type deduction of base types when used in covariant generics

I stumbled upon a case in where automatic type deduction of the .NET 4.0 MS-C# compiler failed and I had to specify the type "by hand". This is not a big problem for me, but enough to get me curious why the compiler can not automatically find the…
Imi
  • 1,579
  • 1
  • 12
  • 22
1
vote
4 answers

Virtual function return type

I have in a base class pure virtual function defined as virtual int GetData() const = 0; In each of derived classes I define an enum and try to override GetData function return (derived class specific enum) value; For example: class Derived1 :…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
1
vote
1 answer

pure virtual functions overloading and covariant return types with multiple inheritance

I have to revise my previous question. Are there any limitations for covariant return types to be created with multiple inheritance? Code below presents the problem. If we uncomment for class IDFOutputPin inheritance from IDFPin the whole code…
mati
  • 39
  • 2
0
votes
0 answers

Can I include covariates in a one-way repeated measures ANOVA? (ANCOVA?) What do results tell me?

I want to test the effect of a suicide prevention film on help-seeking. I have help-seeking intentions as an outcome variable and measured this variable at three time points (pre, post, follow-up) in 50 participants. To analyse the data I would…
0
votes
0 answers

Sex as a covariant in one compartment modelling . Is the code correct? I get a very similar objf to the model with not covariant

I have to create a co-variate model however, I am not sure of how to do with a categorical variable such sex. The obfj is identical to the obfj of the model with not covariant. my data source is amox <-…
0
votes
0 answers

How to add entity_effects to correspond to variable?

I wanted to add entity_effects that correspond with my column host_id, and add drop_absorbed = True to define the data. panel_data This is what I tried: panel.reset_index(inplace = True) modFE = PanelOLS(panel.price_USD2,…
lmes
  • 3
  • 2
0
votes
2 answers

What Type to use for Generic IList Method

I have tried to write a method that converts any IList of things into a comma-separated list of those things as a string. It looks like this: public static string ToStringList(this T source) where T : IList { string list_string =…
High Plains Grifter
  • 1,357
  • 1
  • 12
  • 36
0
votes
1 answer

What are the rules for using out keyword in generics type without getting a compilation error

In Kotlin i am learning about covariant(a subtype can be used in place of a super type). They wrote there something like a rule. but it seems wrong for me. It is written: You can’t, however, use out if the class has function parameters or…
Eitanos30
  • 1,331
  • 11
  • 19
0
votes
2 answers

Contravariance usage in Scala

As per the definition of contravariance (super class instances will be accepted), my last statement in the below code snippet, should be accepted; but it is thrown with type error. Can you please correct my understanding. class A class B extends…
user3103957
  • 636
  • 4
  • 16
0
votes
1 answer

Issue with casting

import scala.annotation.unchecked.uncheckedVariance import scala.collection.immutable.Queue import scala.collection.mutable.ListBuffer abstract class Exp[+T:Manifest] { // constants/symbols (atomic) def tp: Manifest[T…
PheniX Tylor
  • 41
  • 1
  • 4
0
votes
0 answers

The covariant type is not used as a generic constraint for the interface methods, why? (C#)

The problem: interface ICovariant { // The following statement generates a compiler error // because you can use only contravariant or invariant types // in generic constraints. // void DoSomething() where T : R; } Why is…
0
votes
0 answers

ANCOVA with afex in R: Error: Empty cells in between-subjects design, however no NA's

I am performing a factorial ANCOVA in R using aov_ez from the afex package. I have two binary covariates both coded as factors and dummies (0 and 1). There is no missing data in the dataset or in the covariate columns. However, when I run aov_ez it…
0
votes
1 answer

Question about covariant parameters in Java

I have this piece of code: class X { int x = 1; } class Y extends X { int y = 2; } class Z extends Y { int z = 3; } class A { public Y metodo1(Y y) { System.out.println("Metodo1 de A"); return new Y(); } …
Awacate
  • 125
  • 2
  • 10