Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
Created January 31, 2019 06:17
Show Gist options
  • Save sir-wabbit/a075f6725d2c6fc4ac057a976795a77f to your computer and use it in GitHub Desktop.
Save sir-wabbit/a075f6725d2c6fc4ac057a976795a77f to your computer and use it in GitHub Desktop.
data CoalgT f a b = CoalgT (forall z. f b z -> a -> z)
-- a -> ExprF b
-- ~ a -> (forall z. (ExprF b -> z) -> z)
-- ~ a -> (forall z. ExprA b z -> z)
-- ~ CoalgT ExprA a b
data PatternF f a = PatternF (forall z. f a z -> z)
-- ExprF a
-- ~ forall z. (ExprF a -> z) -> z
-- ~ forall z. ExprA a z -> z
instance Profunctor f => Functor (PatternF f) where
fmap f (PatternF run) = PatternF (\alg -> run (dimap f id alg))
instance Profunctor f => Profunctor (CoalgT f) where
dimap l r (CoalgT run) = CoalgT $ \alg -> \a -> run (dimap r id alg) (l a)
class Profunctor f => Recursive t f | t -> f where
embed :: f t t
cata :: forall z. f z z -> t -> z
project :: forall z. f t z -> t -> z
embedF :: PatternF f t -> t
embedF (PatternF run) = run embed
patternF :: forall a b. f a b -> (PatternF f a -> b)
patternF alg = \(PatternF run) -> run alg
unPatternF :: forall a b. (PatternF f a -> b) -> f a b
unPatternF alg = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment