aelve / haskell-issues

An unofficial issue tracker for all things Haskell-related
18 stars 0 forks source link

free: hoistCofree should be generalized #5

Open Gurkenglas opened 8 years ago

Gurkenglas commented 8 years ago

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
neongreen commented 8 years ago

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

fumieval commented 8 years ago

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

neongreen commented 8 years ago

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

neongreen commented 8 years ago

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