Last active
December 22, 2023 11:07
-
-
Save ymdryo/dd093ad5ac2d418407f2ef43469faede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
関連する定義はこの辺りに
https://github.com/sayo-hs/heftia/blob/80be242c1fa8dec3a37d5dbf2697321037effe29/heftia/src/Control/Monad/Trans/Heftia/Tree.hs