这个“派生新类型”语法是什么?

typ*_*ris 3 haskell deriving derivingvia

从我读过的一篇博客文章

-- | 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 ()
Run Code Online (Sandbox Code Playgroud)

那是什么deriving newtype语法?它是哪个扩展名,它有什么作用?请在 anwser 中提供指向其文档的链接。

sna*_*nak 7

它让 GHC 使用GeneralizedNewtypeDeriving策略来派生实例。您需要启用DerivingStrategies扩展。