Let's say I have these classes: And then I declare a variable like this: Now, Action<T> is contravariant on T, so I can do this: That m ...
Let's say I have these classes: And then I declare a variable like this: Now, Action<T> is contravariant on T, so I can do this: That m ...
Dart unfortunately lacks (by design) the ability to specify invariant or contravariant type parameters. So when I need them, how do I work around thei ...
Preemptive apologies if I'm abusing the term, but I'm able to implement an interface in typescript which I believe is not type safe, for example: int ...
I do not fully understand how variance in Generics work. In the code below the classes are as follows Any -> Mammals -> Cats. Any is the superty ...
I have a function that expects a short lived object. I would expect that I would be able to always pass it a long lived object. But I am getting a str ...
The IComparable<in T> interface is defined as Contra-Variance. Contra-Variance wrote the following code to check what constraint there is. pub ...
As an exploration of how variance works, I've come up with this type that could be both a Functor and a Contravariant depending on its arguments: new ...
Let's say we have some interface like this: I'm using Foo a lot in my codebase, but I wish to add the TIn extends T to make it more flexible, to eg ...
Given the following code Why myMapOfFunctions is not a Map[String, Fruit => String] similarly to myMap? I guess because it is about functions bu ...
In golang 1.18 I would like to define a function like follows: func Pipe[A, T1, T2 any](left func(A) T1, right func(T1) T2) func(A) T2 { return f ...
I'm trying to model tagged unions as data. First I create a Tagged utility type, to represent anything intersected with the tag field: Then I crea ...
Consider the following code: The output is: Void ITest<A>.DoTest(A) To me this is not the expected behavior, or at least not the one most d ...
I'm trying to setup a CoR with interfaces where a handler in the chain can be a for a less derived event type using contravariance. I create this inte ...
Suppose the following: Why is that? Isn't T in Do2 guaranteed to inherit from/implement IBase? Edit: forgot where clause in IFace ...
Consider the following program using phantom types: const strlen = (str: string) => str.length; type Const<A, B> = { type: 'Const', value: ...
I have classes B and C inheriting from A. I have some functions that take objects B and C as arguments: I want to create a function that accepts ...
Consider the following type: and two implementations of this type: Now I introduce string names for types: Now I want to construct function, ...
TypeScript doesn't seem to infer contravariance. Here is an example that illustrates the inconsistency: class Base { base = "I'm base" } class Der ex ...
I'm running into this static type hint mismatch (with Pyright): from __future__ import annotations from typing import AnyStr, Iterable def foo(i: I ...
I am playing around with the Data.Functor.Contravariant. The phantom method caught my eye: Or, more specifically, the annotation to it: If f is ...