Haskell “派生新类型”语法是什么?
从我读到的一篇博客文章Haskell “派生新类型”语法是什么?,haskell,Haskell,从我读到的一篇博客文章 -- | 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
-- | 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 ()
thas派生新类型的语法是什么?
它是哪个分机,它做什么?
请在anwser中提供指向其文档的链接。它允许GHC使用GeneralizedNewtypeDeriving
策略来派生实例。您需要启用扩展。将deriving via
理解为“广义GeneralizedNewtypeDeriving
”:派生新类型(F,a,M)
可以替换为通过M派生(F,a,M)
。我不建议在实践中使用它(当您通过newtype
的底层表示进行派生时,始终使用派生newtype
),但最好将其理解为另一个特性的特例。