ekmett / kan-extensions

Kan extensions, Kan lifts, the Yoneda lemma, and (co)monads generated by a functor
Other
79 stars 33 forks source link

Add polymorphic improve variant #22

Open treeowl opened 8 years ago

treeowl commented 8 years ago
improve :: Functor f => (forall m. MonadFree f m => m a) -> Free f a
improve m = lowerCodensity m

lowerCodensity :: Monad f => Codensity f a -> f a

The basic idea of improve is that the passed action does not depend on the choice of free monad construction (I don't actually remember why this matters, but that's the idea). The specific choice of Free f as the result monad, however, seems to be arbitrary. Thus

improve' :: (Functor f, MonadFree f m') =>
            (forall m . MonadFree f m => m a) -> m' a
improve' m = lowerCodensity m
treeowl commented 8 years ago

Unrelated: why improve m = lowerCodensity m and not just improve = lowerCodensity?