Skip to content

Instantly share code, notes, and snippets.

@ymdryo
Last active December 22, 2023 11:07
Show Gist options
  • Save ymdryo/dd093ad5ac2d418407f2ef43469faede to your computer and use it in GitHub Desktop.
Save ymdryo/dd093ad5ac2d418407f2ef43469faede to your computer and use it in GitHub Desktop.
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
newtype Heftia h a = Heftia {unHeftia :: FreerTreeT (h (Heftia h)) Identity a}
deriving (Functor, Applicative, Monad)
to :: HFunctor h => Heftia h a -> HeftiaTree h a
to (Heftia (FreerTreeT (FreeT (Identity f)))) =
HeftiaTreeT . HeftyT . Identity $ case f of
Pure x -> Pure x
Free (Coyoneda k h) ->
Free
. HCoyoneda
$ Coyoneda
(unHeftiaTreeT . to . Heftia . FreerTreeT . k)
(hfmap (unHeftiaTreeT . to) h)
from :: HFunctor h => HeftiaTree h a -> Heftia h a
from (HeftiaTreeT (HeftyT (Identity f))) =
Heftia . FreerTreeT . FreeT . Identity $
case f of
Pure x -> Pure x
Free (HCoyoneda (Coyoneda k h)) ->
Free $
Coyoneda
(unFreerTreeT . unHeftia . from . HeftiaTreeT . k)
(hfmap (from . HeftiaTreeT) h)
@ymdryo
Copy link
Author

ymdryo commented Dec 8, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment