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