Haskell “是否有标准名称或实现?”;纯粹适用于“或”吗;?

Haskell “是否有标准名称或实现?”;纯粹适用于“或”吗;?,haskell,applicative,either,Haskell,Applicative,Either,我经常发现我称之为“纯应用或”,即只要我们不实现Monad实例,就可以使用应用实例 newtype AEither e a = AEither { unAEither :: Either e a } deriving Functor -- technically we only need Semigroup instance Monoid e => Applicative (AEither e) where pure a = AEither (pure a) AEither

我经常发现我称之为“纯应用<代码>或<代码>”,即只要我们不实现
Monad
实例,就可以使用
应用<代码>实例

newtype AEither e a = AEither { unAEither :: Either e a }
  deriving Functor

-- technically we only need Semigroup
instance Monoid e => Applicative (AEither e) where
  pure a = AEither (pure a)
  AEither e1 <*> AEither e2 = AEither (combine e1 e2) where
    combine (Right f) (Right a) = Right (f a)
    combine (Left m1) (Left m2) = Left (m1 <> m2)
    combine (Left m ) _         = Left m
    combine _         (Left m ) = Left m
newtype AEither e a=AEither{unaather::ear e a}
派生函子
--技术上我们只需要半群
实例幺半群e=>Applicative(AEither e)其中
纯a=AEither(纯a)
AEither e1 AEither e2=AEither(合并e1 e2),其中
联合收割机(右f)(右a)=右f(a)
联合收割机(左侧m1)(左侧m2)=左侧m1 m2
联合收割机(左m)Um=左m
联合收割机(左m)=左m
它是一个非常有用的
应用程序
,因为它提供了一个比
Monad
实例更强大的“错误摘要”概念。为此,我发现自己在一次又一次地实施它


某处有标准的实例吗?甚至有一个标准名称吗?

这看起来非常类似于
验证
包中的AccValidation类型:

编辑:

特别是以下实例声明:

instance Semigroup err => Apply (AccValidation err) where
  AccFailure e1 <.> AccFailure e2 =
    AccFailure (e1 <> e2)
  AccFailure e1 <.> AccSuccess _  =
    AccFailure e1
  AccSuccess _  <.> AccFailure e2 =
    AccFailure e2
  AccSuccess f  <.> AccSuccess a  =
    AccSuccess (f a)
实例半组错误=>Apply(AccValidation err),其中
AccFailure e1 AccFailure e2=
AccFailure(e1 e2)
AccFailure e1 AccSuccess\=
ACCE1故障
AccSuccess\uuACCFAILURE e2=
ACCE2故障
成功=
AccSuccess(f a)

如果您向我的
错误库提交修补程序,我将接受。我可能最终会这样做。我真的觉得这应该是一种更通用的
applicatives
软件包,以及纯应用产品。有点相关:这似乎是相同的,半群是一个很好的地方。我一直在内部称之为“收集”
,这是同一个!我喜欢这只取决于
半群
,因为这当然是严格必要的。