haskell-issues icon indicating copy to clipboard operation
haskell-issues copied to clipboard

free: hoistCofree should be generalized

Open Gurkenglas opened this issue 8 years ago • 4 comments

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

Gurkenglas avatar Mar 19 '16 19:03 Gurkenglas

Made a pull request: https://github.com/ekmett/free/pull/131

neongreen avatar Apr 05 '16 00:04 neongreen

I think we deliberately use (forall x . f x -> g x) to allow only "legal" transformations.

fumieval avatar Apr 06 '16 02:04 fumieval

Okay, makes sense to me. @Gurkenglas, can this be closed?

neongreen avatar Apr 18 '16 23:04 neongreen

(There's a longer explanation here: https://github.com/ekmett/free/pull/131#issuecomment-207409319.)

neongreen avatar Apr 18 '16 23:04 neongreen