haskell-issues
haskell-issues copied to clipboard
free: hoistCofree should be generalized
It currently has type
Functor f => (forall x. f x -> g x) -> Cofree f a -> Cofree g a
It could have type
Functor f => (f (Cofree g a) -> g (Cofree g a)) -> Cofree f a -> Cofree g a
This would allow me to write things like
import qualified Data.Foldable as F
braid :: Monad m => Cofree m a -> [m a]
braid = F.toList . hoistCofree (Identity . join) . return
Made a pull request: https://github.com/ekmett/free/pull/131
I think we deliberately use (forall x . f x -> g x)
to allow only "legal" transformations.
Okay, makes sense to me. @Gurkenglas, can this be closed?
(There's a longer explanation here: https://github.com/ekmett/free/pull/131#issuecomment-207409319.)