Skip to content

Instantly share code, notes, and snippets.

@JoshuaGross
Created May 14, 2016 04:26
Show Gist options
  • Save JoshuaGross/a30c6518043fa40b676fe08346cad785 to your computer and use it in GitHub Desktop.
Save JoshuaGross/a30c6518043fa40b676fe08346cad785 to your computer and use it in GitHub Desktop.
Haskell - important typeclasses and cotypeclasses
-- none of this is terribly interesting, mostly here for reference
class Functor (f :: * -> *) where
fmap :: (a -> b) -> f a -> f b
(<$) :: a -> f b -> f a
-- The same as Functor!
-- http://stackoverflow.com/questions/34732571/why-there-is-no-cofunctor-typeclass-in-haskell/34732721
class Cofunctor (f :: * -> *) where
fmap :: (b -> a) -> f b -> f a
(<$) :: b -> f a -> f b
class Functor f => Applicative (f :: * -> *) where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: f a -> f b -> f b
(<*) :: f a -> f b -> f a
class Applicative m => Monad (m :: * -> *) where
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
class Functor w => Comonad w where
extract :: w a -> a
duplicate :: w a -> w (w a)
extend :: (w a -> b) -> w a -> w b
class Monoid a where
mempty :: a
mappend :: a -> a -> a
-- http://stackoverflow.com/questions/23855070/what-does-a-nontrivial-comonoid-look-like
class Comonoid m where
destroy :: m -> ()
split :: m -> (m, m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment