Skip to content

Instantly share code, notes, and snippets.

@kakkun61
Created February 21, 2022 15:44
Show Gist options
  • Save kakkun61/f1bd3c7fabbb5f1baa30de111fcae97a to your computer and use it in GitHub Desktop.
Save kakkun61/f1bd3c7fabbb5f1baa30de111fcae97a to your computer and use it in GitHub Desktop.
class FunctorB b where
bmap :: forall f g. (Functor f, Functor g) => (forall a. f a -> g a) -> b f -> b g
instance {-# OVERLAPPABLE #-} (FunctorT (Flip t), FunctorB a) => FunctorB (t a) where
bmap f a = runFlip $ tmap f $ Flip a
instance (FunctorT t, FunctorB a) => FunctorB (Flip t a) where
bmap f a = Flip $ tmap f $ runFlip a
class FunctorT t where
tmap :: forall f g x. (Functor f, Functor g, FunctorB x) => (forall a. f a -> g a) -> t f x -> t g x
default tmap :: forall f g x. (Functor f, Functor g, FunctorB x) => (forall a. f a -> g a) -> t f x -> t g x
tmap f a = runFlip $ bmap f $ Flip a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment