gpt4 book ai didi

haskell - 这个 `deriving newtype` 语法是什么?

转载 作者:行者123 更新时间:2023-12-04 00:16:31 25 4
gpt4 key购买 nike

来 self 阅读的一篇博文

-- | 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 ()

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

最佳答案

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

关于haskell - 这个 `deriving newtype` 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63371148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com