bifunctors
库公开了以下数据类型:
newtype Biff p f g a b = Biff { runBiff :: p (f a) (g b) }
如库中所示,Biff p f g a
是一个 Functor
如果 p
是一个 Bifunctor
并且 g
是一个 Functor
。
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
仿函数g
是一个Applicative
仿函数
这里是相关类型的俄罗斯方 block :
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
这是一个有效的应用实例吗?
最佳答案
换句话说,Biff Either f g a
是两个应用仿函数 Either (f a)
和 g
的组合,因此是一个应用仿函数仿函数。
关于haskell - Biff 是一个应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62480821/