Covariance, contravariance and invariance describe how the existing type inheritance hierarchy changes when subjected to some transformation (such as usage within generics). If the transformation keeps the ordering of the original hierarchy, it is "covariant". If it reverses it, it is "contravariant". If it breaks it, it is "invariant".
Questions tagged [invariance]
49 questions
1
vote
0 answers
mirt package R: How to create a independent model with multigroup() function
I am having some issues with the multipleGroup() function in R and I really hope there's someone who can help me out. I want to create first an independent, not constrained model where all the parameters may vary for both groups, but I am getting…

Gretaku
- 11
- 1
1
vote
1 answer
Is this a valid example of Class invariances using php 7 asserts?
I am trying to understanding a little best the Class Invariances used by Liskov Principle.
I know that some languages like D have native support to invariant, but, using asserts in PHP I've tried combining magic methods and assert:

celsowm
- 846
- 9
- 34
- 59
1
vote
0 answers
Why can this concrete generic type not be replaced by a concrete type fulfilling the same contract?
Why can in the implementation class Node the generic type of IEdge not be replaced by the concrete implementation class Edge:IEdge.
// For interface definitions INode and IEdge
interface INode
where TNodeN : INode

Kevin Streicher
- 484
- 1
- 8
- 25
1
vote
0 answers
Contravariant or invariant interfaces in the same List in C#
I am stuck with a problem about interface covariance and contravariance. I have two generic interfaces:
public interface IConfigConsumer where T : IConfiguration
{
void Load(T configuration);
}
public interface IConfigProvider where T…

Travis182HUN
- 11
- 2
1
vote
2 answers
Why can find `Functor` instance for Tree but not for Branch or Leaf?
I have the following Functor definition:
import cats.Functor
import cats.syntax.functor._
object Theory {
implicit val treeFunctor: Functor[Tree] =
new Functor[Tree] {
def map[A, B](fa: Tree[A])(f: A => B): Tree[B] =
fa match…

softshipper
- 32,463
- 51
- 192
- 400
1
vote
0 answers
Path analysis invariance
I am running a path analysis in order to examine its invariance between two different cultures. When I examine the fit and the parameters of the path model seperately for each culture, I find that some paths are significant in both cultures, whereas…

Nikos
- 11
- 2
1
vote
1 answer
SLS3.2.10, what's wrong about invariance here?
Scala newbie running into a problem here:
val cache: LoadingCache[Long, String] = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader [Long, String] {
override def…

Shi Chen
- 91
- 2
- 7
1
vote
1 answer
IntelliJ IDEA: default parameter values in Scala
In Scala REPL I can use Seq[String]() as a default value for a parameter of type Seq[T].
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions to have them evaluated.
Type :help for more…

Marcus
- 1,857
- 4
- 22
- 44
1
vote
1 answer
Why invariant generic type parameterized with subclass of upper bounds fails to conform?
Given:
class Invar[T]
trait ExtendsAnyref extends AnyRef
def f(a: Invar[ExtendsAnyref]) = {}
The following is erroneous
scala> val x: Function1[Invar[_ <: AnyRef], Unit] = f
:13: error: type mismatch;
found : Invar[ExtendsAnyref] =>…

Adam Mackler
- 1,980
- 1
- 18
- 32
0
votes
0 answers
Invariance Model: Scarla, CFI=1?
CFI reading
I ran the invariance model with 6 experimental group. While the metric model is slightly worse than the configural model, the scalar suddenly move to another direction with CFI being 1. see the screenshot.
`config <- cfa(model3,
…

Jennifer Lau
- 3
- 1
0
votes
0 answers
Measurement invariance in Lavaan (subgroup analysis); Warning: covariance matrix of latent variables is not positive definite
I have a good fitting CFA model and am now conducting some additional analyses by different subgroups (e.g., gender, age, education, ...). Specifically, I'm calculating fit indices for measurement invariance (configural, metric, scalar). Everything…

Mary
- 1
- 1
0
votes
0 answers
For type argument how to prohibit the use of covariant subtypes as if the type of the argument's constraint was invariant?
Suppose I want to create a generic class for collecting validation errors of entity's field.
For clarity let's define 2 independent entity classes:
class Person(val name: String, val age: UInt)
class Employer(val name: String, val…

Kirill
- 6,762
- 4
- 51
- 81
0
votes
1 answer
Mypy: how to specify list (or sequence) of mixed types?
Here some code:
import typing
class A:
def f(self):
print("A")
class B:
def f(self):
print("B")
C = typing.Union[A,B]
Sequence_C = typing.Sequence[C]
a = A()
b = B()
d : Sequence_C = [a]+[b]
mypy provides this…

Vince
- 3,979
- 10
- 41
- 69
0
votes
0 answers
R code error testing measurement invariance
I'm trying to text measurement invariance in a sample with continuous measures, no missing data, and 190 and 208 samples in each group. Whenever I try to test configural invariance I get the following error message:
Error in crossprod(Diff,…
0
votes
1 answer
How to analyze generic lifetime when it is relevant to variance
0 // code snippet 1
1
2 struct MutStr<'a >{
3 s: &'a mut &'a str,
4 }
5
6 fn main() {
7 let mut s: &'static str = "hello";
8 *MutStr{
9 s: &mut s,
10 }.s = "world";
11 println!("{}", s);
12 }
Rust Playground…

Steve Lau
- 658
- 7
- 13