errors/InvalidNewtypeInstance.md
InvalidNewtypeInstance Errornewtype ManyErrors e a = ManyErrors (Either e (Maybe a))
derive newtype instance manyErrorsFunctor :: Functor (ManyErrors e)
While ManyErrors is a valid newtype, its underlying representation is not a
type for which a Functor instance already exists. Most causes of this error are
due to the newtype being some composition of other types (in our case, Either
and Maybe) instead of just one type.
import Data.Functor.Compose (Compose)
newtype ManyErrors e a = ManyErrors (Compose (Either e) Maybe a)
derive newtype instance manyErrorsFunctor :: Functor (ManyErrors e)
This works because Compose f g is a functor whenever f and g are functors.
Otherwise, we would need to explicitly write the instance ourselves.