What about having the class head beMonad m, Functor f=> … MonadFree f m ..?
Is the motivation here to have a more performant liftF?What are some examples of more efficient implementations for current instances and what’s the performance delta?
_______________________________________________On Fri, Jul 16, 2021 at 6:53 PM David Feuer <david.feuer@gmail.com> wrote:Another flavor would be to leave liftF alone and add a method that does the same thing with a different name. This would preserve performance characteristics for instances like FT, for situations where the current implementation is faster._______________________________________________On Fri, Jul 16, 2021, 4:55 PM David Feuer <david.feuer@gmail.com> wrote:We haveclass Monad m => MonadFree f m | m -> f wherewrap :: f (m a) -> m aliftF :: (Functor f, MonadFree f m) => f a -> m aliftF = wrap . fmap pureI propose we change this toclass Monad m => MonadFree f m | m -> f wherewrap :: f (m a) -> m aliftF :: f a -> m adefault liftF :: Functor f => f a -> m aliftF = wrap . fmap pureand add a functiondefaultWrap :: MonadFree f m => f (m a) -> m adefaultWrap = join . liftFThis change is not strictly backwards compatible. Some instances might, hypothetically, have to add a Functor constraint. For example, the classic Control.Monad.Free and Control.Monad.Trans.Free would need them. However, those instances already have (currently redundant) Functor constraints, so that doesn't seem like a big deal.An alternative would be to hew more strictly to backwards compatibility by placing a Functor f constraint on liftF. This seems a bit sad for "freer" instances that don't need it. For example, we havenewtype FT f m a = FT{ runFT :: forall r. (a -> m r) -> (forall x. (x -> m r) -> f x -> m r) -> m r }for whichliftF :: f a -> FT f m aliftF fa = FT $ \pur bndf -> bndf pur faPull request at https://github.com/ekmett/free/pull/208
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries