3

From a blog post I read

-- | Newtype for disabling logging
newtype NoLoggingT m a
  = NoLoggingT { runNoLoggingT :: m a }
  deriving newtype (Functor, Applicative, Monad)
  deriving (MonadTrans) via IdentityT

instance Monad m => MonadLog (NoLoggingT m) where logLn _ _ = pure ()

What is thas deriving newtype syntax? Which extension is it and what does it do? Please provide a link to its documentation in the anwser.

Iceland_jack
  • 6,848
  • 7
  • 37
  • 46
typetetris
  • 4,586
  • 16
  • 31
  • It is helpful to understand `DerivingVia` as a "Generalized `GeneralizedNewtypeDeriving`": `deriving newtype (F, A, M)` can be replaced with `deriving (F, A, M) via m`. I do not recommend it in practice (always use `deriving newtype` when you are deriving via the underlying representation of a `newtype`) but nevertheless good to understand it as a special case of another feature. – Iceland_jack Aug 27 '20 at 15:58

1 Answers1

7

It lets GHC use GeneralizedNewtypeDeriving strategy to derive instances. You need to enable DerivingStrategies extension.

snak
  • 6,483
  • 3
  • 23
  • 33