Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Forked from tonymorris/TypeClass.hs
Created November 29, 2012 07:20
Show Gist options
  • Save xuwei-k/4167343 to your computer and use it in GitHub Desktop.
Save xuwei-k/4167343 to your computer and use it in GitHub Desktop.
Type-class hierarchy
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, Rank2Types, TypeOperators #-}
newtype Id a =
Id a
data a :\/ b =
Left a
| Right b
data a :/\ b =
(:/\) a b
class Functor f where
($) ::
(a -> b)
-> f a
-> f b
class Functor f => Apply f where
(<*>) ::
f (a -> b)
-> f a
-> f b
class Apply f => Bind f where
(=<<) ::
(a -> f b)
-> f a
-> f b
class Apply f => Applicative f where
pure ::
a
-> f a
class (Applicative f, Bind f) => Monad f where
class Functor f => Alt f where
(<|>) ::
f a
-> f a
-> f a
class Alt f => Plus f where
zero ::
f a
class (Plus f, Monad f) => MonadAlt f where
(<+>) ::
f a
-> f a
-> f a
class MonadAlt f => MonadPlus f where
midentity ::
f a
class Functor f => Extend f where
extend ::
(f a -> b)
-> f a
-> f b
class Extend f => Comonad f where
extract ::
f a
-> a
class Semigroup a where
(<>) ::
a
-> a
-> a
class Splittable a where
split ::
a
-> a :/\ a
class Semigroup a => Monoid a where
identity ::
a
class Semigroup a => Reducer c a where
unit ::
c
-> a
class Foldable t where
foldMap ::
Semigroup m =>
(a -> m)
-> t a
-> m
class Foldable t => Foldable1 t where
foldMap1 ::
Monoid m =>
(a -> m)
-> t a
-> m
class Functor t => Traversable t where
traverse ::
Applicative f =>
(a -> t b)
-> t a
-> f (t b)
class Traversable t => Traversable1 t where
traverse1 ::
Apply f =>
(a -> t b)
-> t a
-> f (t b)
class Functor t => Distributive t where
distribute ::
Functor f =>
(a -> t b)
-> f a
-> t (f b)
class Semigroupoid g where
(.) ::
g a b
-> g b c
-> g a c
class Semigroupoid g => Category g where
id ::
g a a
class Semigroupoid g => Tensor g where
(***) ::
g w x
-> g y z
-> g (w :/\ y) (x :/\ z)
class Semigroupoid g => Choice g where
(|||) ::
g x y
-> g y z
-> g (x :\/ y) z
class Tensor g => First g where
first ::
g a b
-> g (a :/\ c) (b :/\ c)
class (Choice g, First g) => Arrow g where
arr ::
(a -> b)
-> g a b
class Arrow g => ArrowChoice g where
left ::
g a b
-> g (a :\/ c) (b :\/ c)
class ArrowAlt g where
(.+.) ::
g a b
-> g a b
-> g a b
class ArrowAlt g => ArrowPlus g where
aidentity ::
g a b
class MonadTrans t where
lift ::
Monad m =>
m a
-> t m a
class MonadTrans t => BindTrans t where
liftB ::
Bind f =>
f a
-> t f a
class MonadTransform t where
transform ::
(Monad f, Monad g) =>
(forall z. f z -> g z)
-> t f a
-> t g a
class MonadTransform t => BindTransform t where
transformB ::
(Bind f, Bind g) =>
(forall z. f z -> g z)
-> t f a
-> t g a
class ComonadTrans t where
lower ::
Comonad f =>
t f a
-> f a
class ComonadTrans t => ExtendTrans t where
lowerB ::
Extend f =>
t f a
-> f a
class ComonadHoist t where
cohoist ::
Comonad f =>
t f a
-> t Id a
class ComonadHoist t => ExtendHoist t where
cohoistB ::
Extend f =>
t f a
-> t Id a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment