Created
November 28, 2019 15:00
-
-
Save sjoerdvisscher/12504aced97f653de6e37d66a6d0c6c9 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