2 ms·
You think of it like a generator. Before I wrote something like ana : Step f seed -> seed -> Nu f but we might define `Nu f` using an existential to just
by tel 13y ago
You think of it like a generator. Before I wrote something like
ana : Step f seed -> seed -> Nu f
but we might define `Nu f` using an existential to just be
data Nu f = forall seed . (Step f seed, seed)
and then you can write an eliminator for this type which just handles each step. So, `repeat` might look like
data ListF a x = Nil | Cons a x
repeat :: a -> Nu (ListF a)
repeat a = Nu (\x -> Cons x x, a)
and then `take` will be a parametric catamorphism on Nat which just repeatedly creates new layers and consumes them. Together these form a thing called a hylomorphism.