Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Created December 11, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Solonarv/16e2c3d1301a99b6c26f59d6a261884b to your computer and use it in GitHub Desktop.
Save Solonarv/16e2c3d1301a99b6c26f59d6a261884b to your computer and use it in GitHub Desktop.
Monadic Loeb fixed-point combinator
-- standard "loeb" combinator
-- https://github.com/quchen/articles/blob/master/loeb-moeb.md
loeb :: Functor f => f (f a -> a) -> f a
loeb x = go where go = fmap ($ go) x
-- "monadic loeb"?
loebM :: (Traversable t, Monad m) => t (t a -> m a) -> m (t a)
loebM = sequenceA . loeb . fmap (\f xs -> f =<< sequenceA xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment