Type-class hierarchy
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
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, Rank2Types, TypeOperators #-} | |
module TypeClass where | |
class Contravariant f where | |
(-$) :: | |
(a -> b) | |
-> f b | |
-> f a | |
newtype Id a = | |
Id a | |
data a :\/ b = | |
L a | |
| R 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 Semigroup a => Monoid a where | |
identity :: | |
a | |
class Semigroup a => Reducer c a where | |
unit :: | |
c | |
-> a | |
class Foldable t where | |
foldMap :: | |
Monoid m => | |
(a -> m) | |
-> t a | |
-> m | |
class Foldable t => Foldable1 t where | |
foldMap1 :: | |
Semigroup m => | |
(a -> m) | |
-> t a | |
-> m | |
class Functor t => Traversable t where | |
traverse :: | |
Applicative f => | |
(a -> f b) | |
-> t a | |
-> f (t b) | |
class Traversable t => Traversable1 t where | |
traverse1 :: | |
Apply f => | |
(a -> f 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 (~>) where | |
(.) :: | |
b ~> c | |
-> a ~> b | |
-> a ~> c | |
class Semigroupoid (~>) => Category (~>) where | |
id :: | |
a ~> a | |
-- what constraints belong here? | |
class Semigroupoid (~>) => Tensor (~>) where | |
(***) :: | |
a ~> b | |
-> c ~> d | |
-> (a :/\ c) ~> (b :/\ d) | |
-- what constraints belong here? | |
class Semigroupoid (~>) => Disjoint (~>) where | |
(+++) :: | |
a ~> b | |
-> c ~> d | |
-> (a :\/ c) ~> (b :\/ d) | |
-- what constraints belong here? | |
class Semigroupoid (~>) => CombineIn (~>) where | |
(*-*) :: | |
x ~> a | |
-> x ~> b | |
-> x ~> (a :/\ b) | |
-- what constraints belong here? | |
class Semigroupoid (~>) => ChooseIn (~>) where | |
(>+<) :: | |
a ~> x | |
-> b ~> x | |
-> (a :\/ b) ~> x | |
-- what constraints belong here? | |
class Semigroupoid (~>) => CombineOut (~>) where | |
(>*<) :: | |
a ~> x | |
-> b ~> x | |
-> (a :/\ b) ~> x | |
-- what constraints belong here? | |
class Semigroupoid (~>) => ChooseOut (~>) where | |
(+-+) :: | |
x ~> a | |
-> x ~> b | |
-> x ~> (a :\/ b) | |
class (Semigroupoid (~>), Tensor (~>)) => First (~>) where | |
first :: | |
a ~> b | |
-> (a :/\ c) ~> (b :/\ c) | |
class (Semigroupoid (~>), Tensor (~>)) => Second (~>) where | |
second :: | |
a ~> b | |
-> (c :/\ a) ~> (c :/\ b) | |
class (Category (~>), First (~>), Second (~>), CombineIn (~>), ChooseIn (~>)) => Arrow (~>) where | |
into :: | |
(a -> b) | |
-> a ~> b | |
class (Semigroupoid (~>), Disjoint (~>)) => Left (~>) where | |
left :: | |
a ~> b | |
-> (a :\/ c) ~> (b :\/ c) | |
class (Semigroupoid (~>), Disjoint (~>)) => Right (~>) where | |
right :: | |
a ~> b | |
-> (c :\/ a) ~> (c :\/ b) | |
class (Category (~>), Left (~>), Right (~>), CombineOut (~>), ChooseOut (~>)) => Split (~>) where | |
out :: | |
(a -> b) | |
-> b ~> a | |
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 | |
---- | |
instance Functor ((->) t) where | |
f $ g = | |
\x -> f (g x) | |
instance Apply ((->) t) where | |
f <*> g = | |
\x -> f x (g x) | |
instance Bind ((->) t) where | |
f =<< g = | |
\x -> f (g x) x | |
instance Applicative ((->) t) where | |
pure a = | |
\_ -> a | |
instance Monad ((->) t) where | |
instance Semigroupoid (->) where | |
f . g = | |
\x -> f (g x) | |
instance Category (->) where | |
id a = | |
a | |
instance Tensor (->) where | |
f *** g = | |
\(a :/\ c) -> (f a :/\ g c) | |
instance Disjoint (->) where | |
f +++ g = | |
\q -> case q of | |
L a -> L (f a) | |
R b -> R (g b) | |
instance ChooseIn (->) where | |
f >+< g = | |
\q -> case q of | |
L a -> f a | |
R b -> g b | |
instance CombineIn (->) where | |
f *-* g = | |
\x -> f x :/\ g x | |
instance First (->) where | |
first f = | |
\(a :/\ c) -> (f a :/\ c) | |
instance Second (->) where | |
second f = | |
\(a :/\ c) -> (a :/\ f c) | |
instance Arrow (->) where | |
into f = | |
f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment