Search code examples
haskellderivingderivingvia

What is this `deriving newtype` syntax?


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.


Solution

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