I've been looking at the recursion-schemes library, and I'm very confused about what prepro is supposed to be used for, or even what it does. The description of it as 'Fokkinga's prepromorphism' isn't very informative, and the signature (prepro :: Corecursive t => (forall b . Base t b -> Base t b) -> (Base t a -> a) -> t -> a) looks very similar to cata (the catamorphism) but with an extra argument, whose intent is unclear. Would someone be able to explain what this function is meant to do?
What is Fokkinga's prepromorphism meant to do?
561 Views Asked by Koz Ross At
1
catacollapses a value: it unwraps one layer of the functor (project), collapses the interior values recursively (fmap (cata f)), and then collapses the whole thing.preproalso collapses a value, but it also appliese(a natural transformationBase t ~> Base t) as it does so. Notice thatcata embedmeansid(except it's able to turn e.g.[Int]intoFix (ListF Int)), because it collapses the functor layers by embedding them back into the output value:cata (embed . e)is rather similar, except it transforms each layer of the functor as it passes down. Becauseeis a natural transformation, it cannot peer at whatever is inside the layers as they fall; it can only reorganize the structure of the layer (this includes shuffling the inner layers around as long is it doesn't actually look into the inner layers).So, back to
prepro e f. It collapses a value, by first peeling off the outer layer, then "rewriting" the inner layers withe, collapsing the inner values recursively, and then collapsing the whole thing. Note that since the recursion is withpreproitself, the deeper a layer is inside the value, the more times it gets rewritten bye.Demonstration