Make DeriveFunctor Bifunctor-aware
Can we integrate Bifunctor into the DeriveFunctor pipeline since Bifunctor is in base?
When it encounters a binary type constructor Bi ?x ?y
, if the last type argument appears (positively) in ?x
it should check whether Bifunctor Bi
holds and use bimap
to map over it.
{-# Language DeriveFunctor #-}
{-# Language DerivingStrategies #-}
-- • Can't make a derived instance of
-- ‘Functor Foo’ with the stock strategy:
-- Constructor ‘F’ must use the type variable only as the last argument of a data type
-- • In the newtype declaration for ‘Foo’
newtype Foo a = Foo (Either [a] [a])
deriving stock Functor
This should to derive Functor (Function іn)
, assuming the appropriate functors.
type Function :: Type -> Type -> Type
newtype Function іn out = Functor
{ funcApply :: FData -> [Exp іn] -> Either (RawException out) (Exp out)
}
deriving stock Functor