我hoistFree从免费包hoistFreeM中推广fmap到类似于人们可以推广的方式Data.Traversable.mapM.
import Control.Monad
import Control.Monad.Free
import Data.Traversable as T
hoistFreeM :: (Traversable g, Monad m) =>
(forall a. f a -> m (g a)) -> Free f b -> m (Free g b)
hoistFreeM f = go
where go (Pure x) = return $ Pure x
go (Free xs) = liftM Free $ T.mapM go =<< f xs
Run Code Online (Sandbox Code Playgroud)
不过,我不认为有一种方法可以进一步推广它与任何工作Applicative,类似于如何能够推广Data.Traversable.mapM到Data.Traversable.traverse.我对么?如果是这样,为什么?