No, you can't write this function for Cofree
in general. Consider f ~ Proxy
(where data Proxy a = Proxy
):
xembed :: Proxy (Cofree Proxy a) -> Cofree Proxy a
-- i.e.
xembed :: () -> a
Has to get an a
out of nowhere.
However, you can write xembed
for Free
: wrap :: f (Free f a) -> Free f a
. And similarly you can't write xproject :: Free f a -> f (Free f a)
in general.