Buscar..


Cofree Empty ~~ Empty

Dado

data Empty a

tenemos

data Cofree Empty a
   --  = a :< ...  not possible!

Cofree (Const c) ~~ escritor c

Dado

data Const c a = Const c

tenemos

data Cofree (Const c) a
     = a :< Const c

que es isomorfo para

data Writer c a = Writer c a

Cofree Identity ~~ Stream

Dado

data Identity a = Identity a

tenemos

data Cofree Identity a
     = a :< Identity (Cofree Identity a)

que es isomorfo para

data Stream a = Stream a (Stream a)

Cofree Maybe ~~ NonEmpty

Dado

data Maybe a = Just a
             | Nothing

tenemos

data Cofree Maybe a
     = a :< Just (Cofree Maybe a)
     | a :< Nothing

que es isomorfo para

data NonEmpty a
     = NECons a (NonEmpty a)
     | NESingle a

Cofree (Writer w) ~~ WriterT w Stream

Dado

data Writer w a = Writer w a

tenemos

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

que es equivalente a

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

que puede escribirse correctamente como WriterT w Stream con

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

Cofree (Either e) ~~ NonEmptyT (Writer e)

Dado

data Either e a = Left e
                | Right a

tenemos

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

que es isomorfo para

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

o, si se compromete a solo evaluar el registro después del resultado completo, NonEmptyT (Writer e) a con

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

Cofree (Lector x) ~~ Moore x

Dado

data Reader x a = Reader (x -> a)

tenemos

data Cofree (Reader x) a
     = a :< (x -> Cofree (Reader x) a)

que es isomorfo para

data Plant x a
     = Plant a (x -> Plant x a)

También conocido como máquina de Moore .



Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow