Skip to content

Instantly share code, notes, and snippets.

@minad
Last active October 18, 2016 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minad/4266443335f0e80d2b14dc7fb4c1a4dd to your computer and use it in GitHub Desktop.
Save minad/4266443335f0e80d2b14dc7fb4c1a4dd to your computer and use it in GitHub Desktop.
-- same as sum below
liftSum :: Functor f => Either (f a) (f b) -> f (Either a b)
liftSum = either (Left <$>) (Right <$>)
-- same as comult below
unliftProd :: Functor f => f (a, b) -> (f a, f b)
unliftProd x = (fst <$> x, snd <$> x)
-- same as cosum below
unliftSum :: Comonad f => f (Either a b) -> Either (f a) (f b)
unliftSum x = either (\y -> Left $ fmap (either id (const y)) x)
(\y -> Right $ fmap (either (const y) id) x)
(extract x)
-- could be Monad to make it "more" dual to unliftSum
-- liftProd :: Monad f => (f a, f b) -> f (a, b)
-- same as mult below
liftProd :: Applicative f => (f a, f b) -> f (a, b)
liftProd (x, y) = (,) <$> x <*> y
-- same as applicative
-- strong lax monoidal functor
class Functor f => Monoidal f where
one :: () -> f ()
mult :: (f a, f b) -> f (a, b)
-- oplax monoidal or lax comonoidal functor
class Functor f => CoMonoidal f where
coone :: f () -> ()
comult :: f (a, b) -> (f a, f b)
-- strong lax monoidal functor
class Functor f => Monoidal' f where
zero :: Void -> f Void
sum :: Either (f a) (f b) -> f (Either a b)
-- oplax monoidal or lax comonoidal functor
class Functor f => CoMonoidal' f where
cozero :: f Void -> Void
cosum :: f (Either a b) -> Either (f a) (f b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment