4
我试图找出unfold/coiter
与Control.Comonad.Cofree
和unfold/ana
之间的差异从Data.Control.Fixedpoint
。 Hackage库是resp。 free
和recursion-schemes
。cofree comonad的不可折叠实例
Cofree
和Fix
似乎是堂兄弟,我试图找出什么是可能的与两个和什么是可能的只有他们之一。
我能写的Foldable
为Cofree
一个实例,这样我可以申请cata
从unfold/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
它有可能吗?
你的意思是我不能写'免费monads的'项目,并且'embed'免费的comonads? – nponeccop
是的,我修正了(这是一个cofree comonad,不是免费的comonad!:-))。然而,现在我已经看到了这些类实际上是什么,也许你的'Base'类型不是你想要的(我不太清楚你在那之后是什么)。 'Cofree fa'是'\ self - >(a,f self)'的固定点,'Free fa'是'\ self - >的固定点。既可以是(f self)',也可以是'f' 。 – shachaf