Buscar..


Libre Vacío ~~ Identidad

Dado

data Empty a

tenemos

data Free Empty a
     = Pure a
-- the Free constructor is impossible!

que es isomorfo para

data Identity a
     = Identity a

Identidad libre ~~ (Nat,) ~~ escritor Nat

Dado

data Identity a = Identity a

tenemos

data Free Identity a
     = Pure a
     | Free (Identity (Free Identity a))

que es isomorfo para

data Deferred a
     = Now a
     | Later (Deferred a)

o de manera equivalente (si prometes evaluar primero el primer elemento) (Nat, a) , también conocido como Writer Nat a , con

data Nat = Z | S Nat
data Writer Nat a = Writer Nat a

Libre Tal vez ~~ MaybeT (Escritor Nat)

Dado

data Maybe a = Just a
             | Nothing

tenemos

data Free Maybe a
     = Pure a
     | Free (Just (Free Maybe a))
     | Free Nothing

que es equivalente a

data Hopes a
     = Confirmed a
     | Possible (Hopes a)
     | Failed

o de manera equivalente (si prometes evaluar primero el primer elemento) (Nat, Maybe a) , también MaybeT (Writer Nat) a como MaybeT (Writer Nat) a con

data Nat = Z | S Nat
data Writer Nat a = Writer Nat a
data MaybeT (Writer Nat) a = MaybeT (Nat, Maybe a)

Libre (escritor w) ~~ escritor [w]

Dado

data Writer w a = Writer w a

tenemos

data Free (Writer w) a
     = Pure a
     | Free (Writer w (Free (Writer w) a))

que es isomorfo para

data ProgLog w a
     = Done a
     | After w (ProgLog w a)

o, de manera equivalente, (si se compromete a evaluar el registro primero), Writer [w] a .

Libre (Const c) ~~ O bien c

Dado

data Const c a = Const c

tenemos

data Free (Const c) a
     = Pure a
     | Free (Const c)

que es isomorfo para

data Either c a
     = Right a
     | Left c

Gratis (Reader x) ~~ Reader (Stream x)

Dado

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

tenemos

data Free (Reader x) a
     = Pure a
     | Free (x -> Free (Reader x) a)

que es isomorfo para

data Demand x a
     = Satisfied a
     | Hungry (x -> Demand x a)

o equivalentemente Stream x -> a con

data Stream x = Stream x (Stream x)


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