From 9401a752312a0947dcc56184fadb23d7545329c1 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Sat, 11 Sep 2021 21:20:57 +0300 Subject: [PATCH 1/2] Adds recastCofree --- src/Control/Comonad/Cofree.purs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Control/Comonad/Cofree.purs b/src/Control/Comonad/Cofree.purs index 91bb6e8..046f1b7 100644 --- a/src/Control/Comonad/Cofree.purs +++ b/src/Control/Comonad/Cofree.purs @@ -60,6 +60,16 @@ tail (Cofree c) = snd (force c) hoistCofree :: forall f g. Functor f => (f ~> g) -> Cofree f ~> Cofree g hoistCofree nat (Cofree c) = Cofree (map (nat <<< map (hoistCofree nat)) <$> c) +-- | Recasts a cofree comonad's functor from `f` to `g` by +-- | passing a function in which `g` can annihilate `f`. +recastCofree + :: forall f g a + . Functor f + => (forall z. (Cofree f a -> z) -> f (Cofree f a) -> g z) + -> Cofree f a + -> Cofree g a +recastCofree w (Cofree c) = Cofree ((map <<< map) (w (recastCofree w)) c) + -- | This signature is deprecated and will be replaced by `buildCofree` in a -- | future release. unfoldCofree From 178b16dcea6b1e6ff607caa6eb5d6171ffd4c507 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Sun, 12 Sep 2021 07:05:36 +0300 Subject: [PATCH 2/2] Rewrites hoistCofree using recastCofree --- src/Control/Comonad/Cofree.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Comonad/Cofree.purs b/src/Control/Comonad/Cofree.purs index 046f1b7..209c9a0 100644 --- a/src/Control/Comonad/Cofree.purs +++ b/src/Control/Comonad/Cofree.purs @@ -58,7 +58,7 @@ tail :: forall f a. Cofree f a -> f (Cofree f a) tail (Cofree c) = snd (force c) hoistCofree :: forall f g. Functor f => (f ~> g) -> Cofree f ~> Cofree g -hoistCofree nat (Cofree c) = Cofree (map (nat <<< map (hoistCofree nat)) <$> c) +hoistCofree nat = recastCofree (compose nat <<< map) -- | Recasts a cofree comonad's functor from `f` to `g` by -- | passing a function in which `g` can annihilate `f`.