【问题标题】:Where is `EitherT`'s Applicative instance defined?`EitherT` 的 Applicative 实例在哪里定义?
【发布时间】:2022-10-02 09:00:22
【问题描述】:

根据EitherT 的定义,我看不到here,根据Applicative 的定义,我也看不到here

不应该在 type 模块或 typeclass 模块中定义它,以避免被孤立吗?它在哪里?

    标签: haskell monad-transformers applicative


    【解决方案1】:

    docs page you linked for EitherT 清楚地表明 EitherT 是一个类型别名:

    type EitherT = ExceptT

    ExceptT 键入别名

    这意味着它不能拥有自己的实例;它拥有的任何实例都将为它是别名的类型定义为了;在这种情况下ExceptT

    方便的是,它还链接到ExceptT 的文档。不方便的是,它将ExceptT 的这两次出现链接到不同的URL!其中一个似乎是断开的链接(指向存在于mtl 中的模块,就好像它存在于transformers-either 包中一样),但另一个有效,并显示:

    (Functor m, Monad m) => Applicative (ExceptT e m)
    

    【讨论】:

      【解决方案2】:

      EitherT 定义为 type EitherT = ExceptT。与需要自己的实例的 newtype 包装器不同,type 同义词共享实例。 ExceptT 的实例在 Control.Monad.Trans.Except in the transformers package 中定义。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-30
        • 2012-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多