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} deriving Eq
</div><div>newtype K b a = Const {unConst :: b} deriving Eq</div><div><br> </div><div>instance Functor Id where</div><div> fmap f (Ident x) = Ident $ f x</div><div>instance Functor (K a) where</div><div> 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 => C f a b | f a -> b where
</div><div> ftest :: f a -> 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) => (a -> 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>