Difference between revisions of "Zygohistomorphic prepromorphisms"
Jump to navigation
Jump to search
Tag: visualeditor-switched |
|||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | Zygohistomorphic prepromorphisms are an intentionally overcomplicated combination of recursion-schemes concepts that started as a joke<ref>[https://archive.ph/2Jlo6] Edward Kmett on Twitter, 2019</ref>. |
||
⚫ | |||
⚫ | |||
− | <pre> |
||
+ | |||
− | zygohistomorphic_prepromorphism :: Algebra f b -> GAlgebra f (Cofree f) a -> (f :~> f) -> FixF f -> a |
||
+ | <haskell> |
||
− | zygohistomorphic_prepromorphism f = g_prepro (distZygoT (liftAlgebra f) (distHisto id)) -- unless you want a generalized zygomorphism. |
||
+ | import Control.Morphism.Zygo |
||
− | </pre> |
||
+ | 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. |
||
+ | </haskell> |
||
+ | |||
+ | <references /> |
||
+ | |||
+ | [[Category:Code]] |
||
+ | [[Category:Language extensions]] |
Latest revision as of 15:40, 20 July 2023
Zygohistomorphic prepromorphisms are an intentionally overcomplicated combination of recursion-schemes concepts that started as a joke[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.
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.