1,939 questions
3
votes
1
answer
60
views
Kotlin removeAll function with MutableCollection receiver - both in/out modifiers are used
In Kotlin, the removeAll extension function on MutableCollection with Iterable argument is defined as (see reference here):
@IgnorableReturnValue
fun <T> MutableCollection<in T>.removeAll(
...
3
votes
1
answer
69
views
Kotlin plusAssign function on MutableCollection - Array type parameter T not marked as out
In Kotlin, the plusAssign (+=) operator function on MutableCollection with Array argument is defined as (see reference here):
inline operator fun <T>
MutableCollection<in T>.plusAssign( ...
-2
votes
1
answer
71
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
108
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
31
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
115
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
190
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
73
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 ...
2
votes
1
answer
93
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
57
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
70
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
105
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
34
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
99
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 ...