purescript-contrib / purescript-matryoshka

Generalized folds, unfolds, and traversals for fixed point data structures
Apache License 2.0
59 stars 13 forks source link

Add support for `meta` #13

Open kevinbarabash opened 4 years ago

kevinbarabash commented 4 years ago

I think this is this is the correct implementation (I followed what hylo does but reverse the order):

meta
  ∷ ∀ f a b
  . Functor f
  ⇒ Coalgebra f a
  → Algebra f b
  → a
  → b
meta f g = go
  where
  go a = g $ go <$> f a
eviefp commented 3 years ago

If I understand correctly, this can also be implemented as

meta f g = hylo g f

Which then prompts the question, why not just use hylo? The implementation looks like it's in the reverse order, but it's really not, because the proposed solution also flips the argument order for Algebra and Coalgebra, so it ends up being actually an identical implementation with the first two arguments swapped.