首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cofree comonad的不可折叠实例

cofree comonad的不可折叠实例
EN

Stack Overflow用户
提问于 2013-08-30 21:37:58
回答 1查看 405关注 0票数 4

我正在试图找出unfold/coiterunfold/ana来自Control.Comonad.Cofreeunfold/ana来自Data.Control.Fixedpoint的区别。Hackage库是resp的。freerecursion-schemes.

CofreeFix似乎是表亲,我试图弄清楚两者都有什么可能,只有其中一种是可能的。

我可以为Foldable编写一个Cofree实例,以便将cata应用于从unfold/coiter获得的免费monad

代码语言:javascript
复制
type instance Base (Cofree f a) = f

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

但是我无法构造一个Unfoldable实例:

代码语言:javascript
复制
instance Functor f => Unfoldable (Cofree f a) where
    embed = xembed

xembed :: Functor f => f (Cofree f a) -> Cofree f a 
xembed = undefined

有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-31 01:36:46

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

代码语言:javascript
复制
xembed :: Proxy (Cofree Proxy a) -> Cofree Proxy a
-- i.e.
xembed :: () -> a

得从不知道的地方得到a

但是,您可以为Freewrap :: f (Free f a) -> Free f a编写Freewrap :: f (Free f a) -> Free f a。同样,一般也不能编写xproject :: Free f a -> f (Free f a)

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

https://stackoverflow.com/questions/18541824

复制
相关文章

相似问题

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