Created
July 16, 2015 21:04
-
-
Save raichoo/f1ecaff3a465bbbd797b to your computer and use it in GitHub Desktop.
Comonad: Dual of a Monad
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
{-# LANGUAGE NoImplicitPrelude #-} | |
{-# LANGUAGE RebindableSyntax #-} | |
module Comonad where | |
import Prelude (Functor(..)) | |
class Functor m => Monad m where | |
return :: a -> m a | |
join :: m (m a) -> m a | |
infixl 1 >>= | |
(>>=) :: Monad m => m a -> (a -> m b) -> m b | |
m >>= f = join (fmap f m) | |
class Functor w => Comonad w where | |
extract :: w a -> a | |
duplicate :: w a -> w (w a) | |
infixl 1 =>> | |
(=>>) :: Comonad w => w a -> (w a -> b) -> w b | |
w =>> f = fmap f (duplicate w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment