# Difference between revisions of "Zygohistomorphic prepromorphisms"

From HaskellWiki

m (Error in the use of « à la » (« la » is more or less the French for « the »)) |
m (Minor formatting changes) |
||

(One intermediate revision by one other user not shown) | |||

Line 1: | Line 1: | ||

− | Used when you really need both semi-mutual recursion and history and to repeatedly apply a natural transformation as you get deeper into the functor. Zygo implements semi-mutual recursion like a zygomorphism. Para gives you access to your result à la paramorphism. |
+ | Used when you really need both semi-mutual recursion and history and to repeatedly apply a natural transformation as you get deeper into the functor. <code>Zygo</code> implements semi-mutual recursion like a zygomorphism. ''Para'' gives you access to your result à la paramorphism. |

− | <pre> |
||

+ | <haskell> |
||

import Control.Morphism.Zygo |
import Control.Morphism.Zygo |
||

import Control.Morphism.Prepro |
import Control.Morphism.Prepro |
||

Line 8: | Line 8: | ||

import Control.Functor.Extras |
import Control.Functor.Extras |
||

− | zygohistomorphic_prepromorphism :: Functor f => Algebra f b -> GAlgebra f (Cofree f) a -> (f :~> f) -> FixF f -> a |
||

+ | zygoHistoPrepro |
||

− | zygohistomorphic_prepromorphism f = g_prepro (distZygoT (liftAlgebra f) (distHisto id)) |
||

+ | :: (Unfoldable t, Foldable t) |
||

+ | => (Base t b -> b) |
||

+ | -> (forall c. Base t c -> Base t c) |
||

+ | -> (Base t (EnvT b (Stream (Base t)) a) -> a) |
||

+ | -> t |
||

+ | -> a |
||

+ | zygoHistoPrepro f g t = gprepro (distZygoT f distHisto) g t |
||

-- unless you want a generalized zygomorphism. |
-- unless you want a generalized zygomorphism. |
||

− | </ |
+ | </haskell> |

## Latest revision as of 21:58, 5 April 2021

Used when you really need both semi-mutual recursion and history and to repeatedly apply a natural transformation as you get deeper into the functor. `Zygo`

implements semi-mutual recursion like a zygomorphism. *Para* gives you access to your result à la paramorphism.

```
import Control.Morphism.Zygo
import Control.Morphism.Prepro
import Control.Morphism.Histo
import Control.Functor.Algebra
import Control.Functor.Extras
zygoHistoPrepro
:: (Unfoldable t, Foldable t)
=> (Base t b -> b)
-> (forall c. Base t c -> Base t c)
-> (Base t (EnvT b (Stream (Base t)) a) -> a)
-> t
-> a
zygoHistoPrepro f g t = gprepro (distZygoT f distHisto) g t
-- unless you want a generalized zygomorphism.
```