-
-
Save lemastero/955c02235bd9c166bc60703b0f4396d8 to your computer and use it in GitHub Desktop.
Cofree traversable functor
This file contains hidden or 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
{-# LANGUAGE GADTs #-} | |
import Data.Functor.HCofree | |
import Data.Vec.Lazy | |
import Data.Fin | |
import Data.Type.Nat | |
data Cotra f a where | |
Cotra :: SNat n -> f (Fin n) -> Vec n a -> Cotra f a | |
to :: Functor f => Cotra f a -> HCofree Traversable f a | |
to (Cotra _ fn v) = HCofree (\vb -> fmap (vb !) fn) v | |
cotraUnit :: Traversable f => f a -> Cotra f a | |
cotraUnit = cotraUnit -- see paper | |
from :: HCofree Traversable f a -> Cotra f a | |
from hf = case cotraUnit hf of | |
Cotra n hfn v -> Cotra n (counit hfn) v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment