Haskell Language Common functors as the base of cofree comonads Cofree (Writer w) ~~ WriterT w Stream


Example

Given

data Writer w a = Writer w a

we have

data Cofree (Writer w) a
     = a :< (w, Cofree (Writer w) a)

which is equivalent to

data Stream (w,a)
     = Stream (w,a) (Stream (w,a))

which can properly be written as WriterT w Stream with

data WriterT w m a = WriterT (m (w,a))