Questions tagged [contravariant]
7 questions
10
votes
2 answers
Good examples of not a Contravariant/Contravariant/Divisible/Decidable?
The Contravariant family of typeclasses represents standard and fundamental abstractions in the Haskell ecosystem:
class Contravariant f where
contramap :: (a -> b) -> f b -> f a
class Contravariant f => Divisible f where
conquer :: f a
…

Shersh
- 9,019
- 3
- 33
- 61
5
votes
2 answers
How to understand contravariance when using generic delegates?
I am learning "contravariant generic delegate".
My understanding is:
The "in" keyword specifies that the type parameter is contravariant.
This allows for implicit conversion of delegate types.
If there is no "in" keyword, we don't know if the type…

AdmiralOrange
- 157
- 1
- 14
2
votes
1 answer
How to use contravariant parameters in base class?
In a ASP.NET Web API 2.0-project I want to access with the HTTP verbs GET and POST similar objects from the data model, all implementing the interface ITableRow. So I have a base class offering default implementations of access to these model…

lars k.
- 562
- 4
- 18
1
vote
3 answers
Covariance and Contravariance in Scala
I have a confusion in understanding covariance type being restricted in method parameters. I read through many materials and I am unable to get them the below concept.
class SomeThing[+T] {
def method(a:T) = {...} <-- produces error
}
In the…

user3103957
- 636
- 4
- 16
1
vote
1 answer
Learning how to use contramap when is expected (a -> Maybe b) instead of (a -> b) as the first parameter (Haskell)
I'm studying Haskell and I was asked to solve this exercise:
Implement a new data type named NovoPred that should have a value
constructor with the same name. Also it should have a field named
runNovoPred with type Maybe a -> Bool Then, create…

chrometic
- 81
- 5
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
Difference between 2 class definitions regarding contravariant type?
class Contravariant[-T](val other:T)
error: contravariant type T occurs in covariant position in type T of value other
However this one succeeds
class MMX[-T](x:T)
What is the difference?
Thanks

PheniX Tylor
- 41
- 1
- 4