Haskell Language Common functors as the base of cofree comonads Cofree (Either e) ~~ NonEmptyT (Writer e)


Example

Given

data Either e a = Left e
                | Right a

we have

data Cofree (Either e) a
     = a :< Left e
     | a :< Right (Cofree (Either e) a)

which is isomorphic to

data Hospitable e a
     = Sorry_AllIHaveIsThis_Here'sWhy a e
     | EatThis a (Hospitable e a)

or, if you promise to only evaluate the log after the complete result, NonEmptyT (Writer e) a with

data NonEmptyT (Writer e) a = NonEmptyT (e,a,[a])