Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Good examples of not a Contravariant/Contravariant/Divisible/Decidable?

By : Marie Swarzenski
Date : October 16 2020, 06:10 PM
should help you out The Contravariant family of typeclasses represents standard and fundamental abstractions in the Haskell ecosystem: , (partial answer)
Not contravariant
code :
``````newtype F a = K (Bool -> a)
``````
``````newtype F a = F { runF :: a -> Void }
``````
``````runF (conquer :: F ()) () :: Void
``````
``````instance Decidable F where
lose _ = conquer
choose _ _ _ = conquer
``````
``````instance Monoid m => Divisible (Const m) where
divide _ (Const a) (Const b) = Const (mappend a b)
conquer = Const mempty
``````
``````newtype Predicate a = Predicate (a -> Bool)

instance Divisible Predicate where
divide f (Predicate g) (Predicate h) = Predicate \$ \a -> case f a of
(b, c) -> g b && h c
conquer = Predicate \$ const True

instance Decidable Predicate where
lose f = Predicate \$ \a -> absurd (f a)
choose f (Predicate g) (Predicate h) = Predicate \$ either g h . f
``````

Share :

## Contravariant parameters?

By : user2559820
Date : March 29 2020, 07:55 AM
With these it helps Lambdas are untyped, so this is not possible.
If you don't care about method-arguments, which appears to be the case, why not change the method signature to :
code :
``````public void Do(Action method,
DispatcherPriority priority = DispatcherPriority.Normal)
``````

## Contravariant Value Types

By : Priya Shivakumar
Date : March 29 2020, 07:55 AM
it fixes the issue Covariance and contravariance don't make as much sense on value types, because they are all sealed. Though it's not clear from the documentation, it is valid to use a struct as a co/contravariant type, it's just not always useful. The documentation you reference is most likely referring to that the following is not valid:
code :
``````public struct MyStruct<in T>
``````
``````IRepository<string, Base> b = //something
IRepository<string, Derived> d = b;
``````
``````IEnumerable<Derived> d = //something
IEnumerable<Base> b = d;
``````
``````public interface IRepository<T, in TKey>
where T : class
where TKey : class
``````

## Are there contravariant monads?

By : user3747972
Date : March 29 2020, 07:55 AM
Any of those help Well, of course, it's possible to define it, but I doubt it would be of any use.
There is a popular saying that "monad is just a monoid in a category of endofunctors". What it means is, first of all, that we have a category of endofunctors (meaning, (covariant) functors from some category to itself), and what's more, we have some multiplication on this endofunctors (in this case — composition). And then monad fits into some general framework that we don't have to worry about right now. The point is, there is no "multiplication" of contravariant functors. Composition of two covariant functors is again a covariant functor; but composition of two contravariant functors is not a contravariant functor (rather it's a covariant functor, so, a totally different beast).

## Creating instance for ADT with Contravariant, Divisible, and Decidable

By : Abdul Hamed Ahmed Ki
Date : March 29 2020, 07:55 AM
it should still fix some issue I did it the hard way, without any of the instance, although some nesting of choose might have made it possible.
code :
``````instance Grouping1 JSONTypeF where
grouping1 g = Group \$ \k -> do
kb <- flip getGroup
kc <- flip getGroup
kd <- flip getGroup
ke <- flip getGroup
pure (\obj ->
case obj of
(JObject map) -> kb map
(JArray ary) -> kc ary
(JInvalidArray ary) -> kd ary
(JPrimitive primitive) -> ke primitive
) k
``````

## Building contravariant using Stack leads to constraint error about not being able to deduce Contravariant

By : user2131802
Date : March 29 2020, 07:55 AM
I hope this helps you . It's not you - released packages are not yet caught up for base-4.12.
Now that the Contravariant class is in base, the instance for Backwards should move to transformers, where the latter is defined. There's a patch that adds the instances but I don't think it's been released to Hackage.