capability icon indicating copy to clipboard operation
capability copied to clipboard

Orphan instances might be required on intermediate newtypes

Open aherrmann opened this issue 6 years ago • 0 comments

E.g. in the following code

class Monad m => Logger m where
  logStr :: String -> m ()

newtype TheLoggerReader m a = TheLoggerReader (m a)
  deriving (Functor, Applicative, Monad)
instance  (HasReader "logger" (String -> IO ()) m, MonadIO m) => Logger (TheLoggerReader m)

newtype CountLogM m a = CountLogM (ReaderT CountLogCtx m a)
  deriving (Functor, Applicative, Monad)
  deriving Logger via
    (TheLoggerReader (Field "logger" (Field "logCtx" (MonadReader (ReaderT CountLogCtx m)))))

the deriving Logger via clause requires MonadIO instances for Field and MonadReader. It might happen that a user is forced to define orphan instances for newtypes like MonadReader for type-classes that where not anticipated in this package. This may be unavoidable. However, we should make sure to systematically provide instances for a set of select common type-classes for all newtypes defined in this package.

See https://github.com/tweag/capabilities-via/pull/4#discussion_r208961223

aherrmann avatar Aug 09 '18 15:08 aherrmann