3 ms·
Actually, I realized I follow the "abstract recursion out of your structures" intuition but don't really realize why you chose Cofree instead of some of the oth
by pseudonom- 9y ago
Actually, I realized I follow the "abstract recursion out of your structures" intuition but don't really realize why you chose Cofree instead of some of the other options:
import Control.Monad.Free
import Control.Comonad.Cofree
import Data.Functor.Foldable
data A f
= ANil
| ACons f
type AList a = Cofree A a
a :: AList Int
a = 1 :< ACons (2 :< ACons (3 :< ANil))
data B a f
= B a f
type BList a = Free (B a) ()
b :: BList Int
b = Free (B 1 (Free (B 2 (Free (B 3 (Pure ()))))))
data C a f
= CCons a f
| CNil
type CList a = Fix (C a)
c :: CList Int
c = Fix (CCons 1 (Fix (CCons 2 (Fix (CCons 3 (Fix CNil))))))
You wanted to ensure it's non-empty? Something about the actual Comonad (extend, etc) interface?