首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比夫不是应用性的吗?

比夫不是应用性的吗?
EN

Stack Overflow用户
提问于 2020-06-20 02:04:07
回答 1查看 86关注 0票数 3

bifunctors库公开了以下数据类型:

代码语言:javascript
复制
newtype Biff p f g a b = Biff { runBiff :: p (f a) (g b) }

正如在库中所看到的,如果Biff p f g aBifunctorgFunctor,那么p就是Bifunctor

代码语言:javascript
复制
instance (Bifunctor p, Functor g) => Functor (Biff p f g a) where
  fmap f = Biff . second (fmap f) . runBiff
  {-# INLINE fmap #-}

我怀疑(但尚未证明)在以下情况下,Biff Either f g a是一个应用函子:

  • fAlternative functor
  • gApplicative函子

以下是相关类型的俄罗斯方块:

代码语言:javascript
复制
instance (Alternative f, Applicative g) => Applicative (Biff Either f g a)
  where
  pure a = Biff $ Right $ pure a
  Biff f <*> Biff v = Biff $ go f v
    where
    go (Left  x) (Right _) = Left x
    go (Right _) (Left  x) = Left x
    go (Left  x) (Left  y) = Left $ x <|> y
    go (Right x) (Right y) = Right $ x <*> y

这是一个有效的应用实例吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-20 20:58:02

换句话说,Biff Either f g a是两个应用函子Either (f a)g的组合,因此它是一个应用函子。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62480821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档