cofree comonad的无法折叠的实例

时间:2013-08-30 21:37:58

标签: haskell comonad unfold

我正在尝试找出来自unfold/coiter的{​​{1}}和来自Control.Comonad.Cofree的{​​{1}}之间的区别。 Hackage库是分别的。 unfold/anaData.Control.Fixedpoint

freerecursion-schemes似乎是表兄弟,而我正试图找出两者之间的可能性以及只有其中一种可能的事情。

我可以为Cofree编写Fix的实例,这样我就可以将Foldable应用于从Cofree获得的免费monad:

cata

但我无法构建unfold/coiter实例:

type instance Base (Cofree f a) = f

instance Functor f => Foldable (Cofree f a) where
    project = unwrap

有可能吗?

1 个答案:

答案 0 :(得分:4)

不,你不能为Cofree编写这个函数。考虑f ~ Proxy(其中data Proxy a = Proxy):

xembed :: Proxy (Cofree Proxy a) -> Cofree Proxy a
-- i.e.
xembed :: () -> a

必须无处获得a

但是,您可以为xembedFree撰写wrap :: f (Free f a) -> Free f a。同样,你不能一般地写xproject :: Free f a -> f (Free f a)