Hi,<div><br class="webkit-block-placeholder"></div><div>I have a set of functor definitions with corresponding instances</div><div><br class="webkit-block-placeholder"></div><div><div>newtype Id a = Ident {unIdent :: a} &nbsp; &nbsp; &nbsp; deriving Eq
</div><div>newtype K b a = Const {unConst :: b} &nbsp; &nbsp; &nbsp; deriving Eq</div><div><br>&nbsp;</div><div>instance Functor Id where</div><div>&nbsp;&nbsp; fmap f (Ident x) = Ident $ f x</div><div>instance Functor (K a) where</div><div>&nbsp;&nbsp; fmap f (Const x) = Const x
</div><div>(...)</div><div><br class="webkit-block-placeholder"></div><div>And a class that creates a representation b for a functor f a:</div><div><br class="webkit-block-placeholder"></div><div>class Functor f =&gt; C f a b | f a -&gt; b where
</div><div>&nbsp;&nbsp; ftest :: f a -&gt; b</div><div><br class="webkit-block-placeholder"></div><div>instance C Id a a</div><div>instance C (K b) a b</div><div><br class="webkit-block-placeholder"></div><div>I want to write some function
</div><div><br class="webkit-block-placeholder"></div><div>test :: (C f a b) =&gt; (a -&gt; b)</div><div>test = ftest . undefined</div><div><br class="webkit-block-placeholder"></div><div><div>But, as expected, the type checker claims not to satisfy the context, since the function may be valid for any representable functor, as long as it has an instance.
</div><div>What I would want is to constrain the set of functors that the class applies to, for which I have all the required instances. Is it possible in Haskell?</div><div><br class="webkit-block-placeholder"></div><div>
Sorry if this explanation is confusing.</div><div>Thanks in advance,</div><div>hugo</div></div></div>