2013-08-30 42 views
4

我试图找出unfold/coiterControl.Comonad.Cofreeunfold/ana之间的差异从Data.Control.Fixedpoint。 Hackage库是resp。 freerecursion-schemescofree comonad的不可折叠实例

CofreeFix似乎是堂兄弟,我试图找出什么是可能的与两个和什么是可能的只有他们之一。

我能写的FoldableCofree一个实例,这样我可以申请cataunfold/coiter获得一个免费的单子:

type instance Base (Cofree f a) = f 

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

但我无法构造一个实例:

instance Functor f => Unfoldable (Cofree f a) where 
    embed = xembed 

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

它有可能吗?

回答

4

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

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

要得到一个a无章可循。

但是,您可以写的xembedwrap :: f (Free f a) -> Free f a。一般来说,你不能写xproject :: Free f a -> f (Free f a)

+0

你的意思是我不能写'免费monads的'项目,并且'embed'免费的comonads? – nponeccop

+1

是的,我修正了(这是一个cofree comonad,不是免费的comonad!:-))。然而,现在我已经看到了这些类实际上是什么,也许你的'Base'类型不是你想要的(我不太清楚你在那之后是什么)。 'Cofree fa'是'\ self - >(a,f self)'的固定点,'Free fa'是'\ self - >的固定点。既可以是(f self)',也可以是'f' 。 – shachaf