1,938 questions
-1 votes
1 answer
58 views
Protocols and covariance - How to enable LSP in swift? [duplicate]
I want to keep some graph traversal algorithms as generic as possible and define a protocol for this purpose: protocol Path { var distance : Int { get} var end : Node { get } init (start:...
4 votes
1 answer
105 views
Casting Func<T1, T2> to Func<T1, object> doesn't work with double but works with classes
I have a simple question about covariance/contravariance here. Below, I have a Func<T1, T2> that I need to be casted to Func<T1, object>. In theory, this should be possible, but in ...
0 votes
0 answers
26 views
How to define correlation structure for relational data in glmmTMB?
I have relational data, i.e. observations for pairs of objects. More specifically these are migration rates between plant populations, which I would like to explain by a predictor. The migration rates ...
Advice
0 votes
8 replies
114 views
C# using generic types to represent a partially loaded tree of data
The problem I am trying to solve is representing a partially loaded tree of objects using C# generics. For example, suppose we have the following classes: public class Address { public string ...
4 votes
1 answer
141 views
Why does variance inference for type parameters include `__init__`?
From the official docs: The introduction of explicit syntax for generic classes in Python 3.12 eliminates the need for variance to be specified for type parameters. Instead, type checkers will infer ...
2 votes
1 answer
68 views
Why are type-checkers fine with covariant method parameters when they are in a union?
Method parameters should be contravariant, hence defining a covariant generic should raise a type error. However when using a covariant generic in a union pyright, mypy and pyre-check all do not ...
0 votes
0 answers
83 views
How to reset the covariance matrix in kalman filter
I am simulating a system in which I do not have very accurate information about the measurement and process noises (R and Q). However, although my linear Kalman filter works, it seems that there is ...
2 votes
1 answer
92 views
Function objects with arguments that extend a trait
I have the following code. The compiler complains about the last line. I am wondering why. The WrappedFunction case class takes a function object with trait arguments. When I try to construct a ...
1 vote
0 answers
43 views
How can I assign an `A<B>` to an `A<I>` if `B` implements interface `I` in C#? [duplicate]
Probably there is a duplicate question somewhere but I'm not sure what the correct search terms are. Since a snippet says more than a thousand words: why is this not valid C#? class A<T> { } ...
1 vote
0 answers
50 views
I am not able to typecast the derived class object to Base interface<Base> C# [duplicate]
Can any body help me in succesfully typecasting the derived class object which in real application created from Dependency Injection and retrieved from builder.Services. I am typecasting it to base ...
0 votes
1 answer
69 views
R fastest bivariate regression slope coefficient [closed]
I have tried a number linear regressions, and though the standard ones are all good (e.g., lm.fit is really nicely fast), the fastLM in https://www.rdocumentation.org/packages/RcppEigen/versions/0.3....
2 votes
2 answers
101 views
How to handle common properties in a union of generic class instances
I'm working with a union type of two instances of a generic class. These instances have different property shapes, but they also share common properties. I'm encountering an issue when trying to ...
1 vote
0 answers
32 views
Typescript fails to warn against an invalid method override (because it fails to detect contravariant relationship) [duplicate]
I think TS fails to warn against an invalid method override. In the following code, Dog extends Animal. But Dog is a consumer of DogFood, a subclass of Food, and Animal is a consumer of Food. So the ...
5 votes
0 answers
98 views
Is the inconsistency between conversions allowed by std::not_fn and std::function constructor intended?
If you have something like this, struct Foo { }; constexpr auto pred = [](){ return Foo{}; }; calling std::not_fn(pred) will fail to compile, expectedly. However, adding an explicit conversion ...
2 votes
1 answer
105 views
Why doesn't C# cast Container<Derived> to Container<Base> implicitly?
Consider the following code snippet: class Animal {} class Dog : Animal {} interface IMyContainer<T> { T Get(int i); void Add (T thing); } class MyList<T> : IMyContainer<T> ...