Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created January 21, 2017 15:31
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 deque-blog/cd4974bdec969c0e49f0209f0464ee8b to your computer and use it in GitHub Desktop.
Save deque-blog/cd4974bdec969c0e49f0209f0464ee8b to your computer and use it in GitHub Desktop.
import Control.Monad.Cont
cataCps :: (Traversable f) => (f a -> a) -> Fix f -> a
cataCps algebra expr = runCont (recur algebra expr) id
recur :: (Traversable f) => (f a -> a) -> Fix f -> Cont a a
recur algebra (Fix expr) = do
sub <- sequence $ fmap (recur algebra) expr
return (algebra sub)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment