我正在试图找出unfold/coiter与unfold/ana来自Control.Comonad.Cofree和unfold/ana来自Data.Control.Fixedpoint的区别。Hackage库是resp的。free和recursion-schemes.
Cofree和Fix似乎是表亲,我试图弄清楚两者都有什么可能,只有其中一种是可能的。
我可以为Foldable编写一个Cofree实例,以便将cata应用于从unfold/coiter获得的免费monad
type instance Base (Cofree f a) = f
instance Functor f => Foldable (Cofree f a) where
project = unwrap但是我无法构造一个Unfoldable实例:
instance Functor f => Unfoldable (Cofree f a) where
embed = xembed
xembed :: Functor f => f (Cofree f a) -> Cofree f a
xembed = undefined有可能吗?
发布于 2013-08-31 01:36:46
不,一般不能为Cofree编写这个函数。考虑f ~ Proxy (其中data Proxy a = Proxy):
xembed :: Proxy (Cofree Proxy a) -> Cofree Proxy a
-- i.e.
xembed :: () -> a得从不知道的地方得到a。
但是,您可以为Free:wrap :: f (Free f a) -> Free f a编写Free:wrap :: f (Free f a) -> Free f a。同样,一般也不能编写xproject :: Free f a -> f (Free f a)。
https://stackoverflow.com/questions/18541824
复制相似问题