bifunctors库公开了以下数据类型:
newtype Biff p f g a b = Biff { runBiff :: p (f a) (g b) }正如在库中所看到的,如果Biff p f g a是Bifunctor,g是Functor,那么p就是Bifunctor。
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是一个应用函子:
f是Alternative functorg是Applicative函子以下是相关类型的俄罗斯方块:
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这是一个有效的应用实例吗?
发布于 2020-06-20 20:58:02
换句话说,Biff Either f g a是两个应用函子Either (f a)和g的组合,因此它是一个应用函子。
https://stackoverflow.com/questions/62480821
复制相似问题