Last active
October 18, 2016 15:09
-
-
Save minad/4266443335f0e80d2b14dc7fb4c1a4dd to your computer and use it in GitHub Desktop.
This file contains 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
-- 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 |
This file contains 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
-- 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