Skip to content

Instantly share code, notes, and snippets.

@edwardgeorge
Last active December 19, 2017 10:59
Show Gist options
  • Save edwardgeorge/c5d00b0a0cb03c7d8902660f04443c47 to your computer and use it in GitHub Desktop.
Save edwardgeorge/c5d00b0a0cb03c7d8902660f04443c47 to your computer and use it in GitHub Desktop.
effectful generalised hylomorphism
ghyloM
:: forall w f m n a b. (Comonad w, Traversable f, Monad m, Monad n)
=> (forall x. f (w x) -> w (f x))
-> (forall x. m (f x) -> f (m x))
-> (forall x. w (n x) -> n (w x))
-> (forall x. m (n x) -> n (m x))
-> (f (w b) -> n b)
-> (a -> n (f (m a)))
-> a
-> n b
ghyloM distfw distmf distwn distmn fwalg fmcoalg = fmap extract . go . pure
where
go :: m a -> n (w b)
go = join . fmap j . distmn . fmap fmcoalg
h :: f (w (w b)) -> n (w b)
h = distwn . fmap fwalg . distfw
i :: m (m a) -> n (w (w b))
i = fmap duplicate . go . join
j :: m (f (m a)) -> n (w b)
j = join . fmap h . traverse i . distmf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment