Created
March 24, 2015 23:38
-
-
Save barrucadu/b7ad26b512d709148ae5 to your computer and use it in GitHub Desktop.
Coapplicative functors in Haskell
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
-- Because of the type of 'from', 'Coaplicative' must correspond to "non-empty containers", for the usual hand-wavy definition of "container". | |
class Functor f => Coapplicative f where | |
from :: f a -> a | |
separate :: f (Either a b) -> Either (f a) (f b) | |
instance Coapplicative Identity where | |
from (Identity a) = a | |
separate (Identity (Left a)) = Left (Identity a) | |
separate (Identity (Right b)) = Right (Identity b) | |
-- Silly Haskell having no nontrivial comonoids. | |
class Coapplicative f => Coalternative f where | |
full :: f a -> () | |
full _ = () | |
split :: f a -> f (a, a) | |
split = fmap (\a -> (a,a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment