title: Is it possible to derive an implementation for `Ord` for this tree type? And if not, why?
body: <p>I have defined the following very generic tree type:</p>
  
  <pre><code>data YTree f g a = YNode (f a (g (YTree f g a)))
  </code></pre>
  
  <p>I have defined a functor instance as follows (to demonstrate that it is possible to work with):</p>
  
  <pre><code>instance (Bifunctor f, Functor g) =&gt; Functor (YTree f g) where
      fmap f (YNode m) = YNode $ bimap f (fmap (fmap f)) m
  </code></pre>
  
  <p>I then successfully derived some instances (using <code>StandaloneDeriving</code>, <code>ExplicitForAll</code> and <code>QuantifiedConstraints</code>):</p>
  
  <pre><code>deriving instance (Show a, forall x y. (Show x, Show y) =&gt; Show (f x y), forall z. Show z =&gt; Show (g z)) =&gt; Show (YTree f g a)
  deriving instance (Read a, forall x y. (Read x, Read y) =&gt; Read (f x y), forall z. Read z =&gt; Read (g z)) =&gt; Read (YTree f g a)
  deriving instance (Eq a, forall x y. (Eq x, Eq y) =&gt; Eq (f x y), forall z. Eq z =&gt; Eq (g z)) =&gt; Eq (YTree f g a)
  </code></pre>
  
  <p>However, the following <code>deriving instance</code> clause throws an error when included:</p>
  
  <pre><code>deriving instance (Ord a, forall x y. (Ord x, Ord y) =&gt; Ord (f x y), forall z. Ord z =&gt; Ord (g z)) =&gt; Ord (YTree f g a)
  </code></pre>
  
  <p>Namely, </p>
  
  <pre><code>Data\Tree\Generalized.hs:32:1: error:
      * Could not deduce (Ord z)
          arising from the superclasses of an instance declaration
        from the context: (Ord a,
                           forall x y. (Ord x, Ord y) =&gt; Ord (f x y),
                           forall z. Ord z =&gt; Ord (g z))
          bound by the instance declaration
          at Data\Tree\Generalized.hs:32:1-119
        or from: Eq z
          bound by a quantified context at Data\Tree\Generalized.hs:1:1
        Possible fix: add (Ord z) to the context of a quantified context
      * In the instance declaration for `Ord (YTree f g a)'
     |
  32 | deriving instance (Ord a, forall x y. (Ord x, Ord y) =&gt; Ord (f x y), forall z. Ord z =&gt; Ord (g z)) =&gt; Ord (YTree f g a)
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>as well as another error.</p>
  
  <p>As far as I can see, the implementation would simply be:</p>
  
  <pre><code>instance (Ord a, forall x y. (Ord x, Ord y) =&gt; Ord (f x y), forall z. Ord z =&gt; Ord (g z)) =&gt; Ord (YTree f g a) where
      compare (YNode x) (YNode y) = compare x y
  </code></pre>
  
  <p>This produces the same error, though.</p>
  
  <p>Is it possible to derive this? Why doesn't it work currently? Is it even possible to implement? Am I dead wrong?</p>