Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Reexports important type classes from base, constraints.
Synopsis
- type Functor1 p = ForallF Functor p
- type Applicative1 p = (Functor1 p, ForallF Applicative p)
- type Monad1 p = (Applicative1 p, ForallF Monad p)
- type Alternative1 p = (Applicative1 p, ForallF Alternative p)
- type MonadPlus1 p = (Monad1 p, Alternative1 p, ForallF MonadPlus p)
- class Functor (f :: Type -> Type)
- class Functor f => Applicative (f :: Type -> Type)
- class Applicative m => Monad (m :: Type -> Type)
- class Applicative f => Alternative (f :: Type -> Type)
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type)
- class Forall (ComposeC p f) => ForallF (p :: k2 -> Constraint) (f :: k1 -> k2)
- instF :: forall k2 k1 p (f :: k1 -> k2) (a :: k1). ForallF p f :- p (f a)
- newtype a :- b = Sub (a => Dict b)
- data Dict a where
Constraint synonyms
The quantified super-class instances are explicitly added, since the type system can not deduce them.
type Applicative1 p = (Functor1 p, ForallF Applicative p) Source #
Constraint equivalent to
forall a. Applicative (p a)
type Monad1 p = (Applicative1 p, ForallF Monad p) Source #
Constraint equivalent to
forall a. Monad (p a)
type Alternative1 p = (Applicative1 p, ForallF Alternative p) Source #
Constraint equivalent to
forall a. Alternative (p a)
type MonadPlus1 p = (Monad1 p, Alternative1 p, ForallF MonadPlus p) Source #
Constraint equivalent to
forall a. MonadPlus (p a)
Standard type classes
class Functor (f :: Type -> Type) #
A type f
is a Functor if it provides a function fmap
which, given any types a
and b
lets you apply any function from (a -> b)
to turn an f a
into an f b
, preserving the
structure of f
. Furthermore f
needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap
and
the first law, so you need only check that the former condition holds.
Instances
class Functor f => Applicative (f :: Type -> Type) #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- Identity
pure
id
<*>
v = v- Composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- Homomorphism
pure
f<*>
pure
x =pure
(f x)- Interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Instances
Applicative [] | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Applicative IO | Since: base-2.1 |
Applicative Par1 | Since: base-4.9.0.0 |
Applicative ZipList | f <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative ReadP | Since: base-4.6.0.0 |
Applicative NonEmpty | Since: base-4.9.0.0 |
Applicative Tree | |
Applicative Seq | Since: containers-0.5.4 |
Applicative P | Since: base-4.5.0.0 |
() :=> (Applicative ((->) a :: Type -> Type)) | |
Defined in Data.Constraint ins :: () :- Applicative ((->) a) # | |
() :=> (Applicative []) | |
Defined in Data.Constraint ins :: () :- Applicative [] # | |
() :=> (Applicative Maybe) | |
Defined in Data.Constraint ins :: () :- Applicative Maybe # | |
() :=> (Applicative IO) | |
Defined in Data.Constraint ins :: () :- Applicative IO # | |
() :=> (Applicative (Either a)) | |
Defined in Data.Constraint ins :: () :- Applicative (Either a) # | |
Applicative (Either e) | Since: base-3.0 |
Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Class (Functor f) (Applicative f) | |
Defined in Data.Constraint cls :: Applicative f :- Functor f # | |
Class (Applicative f) (Monad f) | |
Defined in Data.Constraint cls :: Monad f :- Applicative f # | |
Class (Applicative f) (Alternative f) | |
Defined in Data.Constraint cls :: Alternative f :- Applicative f # | |
(Monad m) :=> (Applicative (WrappedMonad m)) | |
Defined in Data.Constraint ins :: Monad m :- Applicative (WrappedMonad m) # | |
(Monoid a) :=> (Applicative ((,) a)) | |
Defined in Data.Constraint | |
(Monoid a) :=> (Applicative (Const a :: Type -> Type)) | |
Defined in Data.Constraint | |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
(Monoid a, Monoid b) => Applicative ((,,) a b) | Since: base-4.14.0.0 |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Applicative m => Applicative (Kleisli m a) | Since: base-4.14.0.0 |
Defined in Control.Arrow | |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
(Profunctor p, Arrow p) => Applicative (Closure p a) | |
Defined in Data.Profunctor.Closed | |
(Profunctor p, Arrow p) => Applicative (Tambara p a) | |
Defined in Data.Profunctor.Strong | |
Applicative (Tagged s) | |
Applicative ((->) r :: Type -> Type) | Since: base-2.1 |
Monoid c => Applicative (K1 i c :: Type -> Type) | Since: base-4.12.0.0 |
(Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
(Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.Base | |
Applicative (Cokleisli w a) | |
Defined in Control.Comonad pure :: a0 -> Cokleisli w a a0 # (<*>) :: Cokleisli w a (a0 -> b) -> Cokleisli w a a0 -> Cokleisli w a b # liftA2 :: (a0 -> b -> c) -> Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a c # (*>) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a b # (<*) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a a0 # | |
Applicative f => Applicative (Star f a) | |
Applicative (Costar f a) | |
Defined in Data.Profunctor.Types | |
Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
class Applicative m => Monad (m :: Type -> Type) #
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following:
- Left identity
return
a>>=
k = k a- Right identity
m
>>=
return
= m- Associativity
m
>>=
(\x -> k x>>=
h) = (m>>=
k)>>=
h
Furthermore, the Monad
and Applicative
operations should relate as follows:
The above laws imply:
and that pure
and (<*>
) satisfy the applicative functor laws.
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
Instances
Monad [] | Since: base-2.1 |
Monad Maybe | Since: base-2.1 |
Monad IO | Since: base-2.1 |
Monad Par1 | Since: base-4.9.0.0 |
Monad ReadP | Since: base-2.1 |
Monad NonEmpty | Since: base-4.9.0.0 |
Monad Tree | |
Monad Seq | |
Monad P | Since: base-2.1 |
() :=> (Monad ((->) a :: Type -> Type)) | |
Defined in Data.Constraint | |
() :=> (Monad []) | |
Defined in Data.Constraint | |
() :=> (Monad IO) | |
() :=> (Monad (Either a)) | |
() :=> (Monad Identity) | |
Monad (Either e) | Since: base-4.4.0.0 |
Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0 |
Defined in Control.Applicative (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in Control.Arrow (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # | |
Class (Applicative f) (Monad f) | |
Defined in Data.Constraint cls :: Monad f :- Applicative f # | |
(Monad m) :=> (Functor (WrappedMonad m)) | |
Defined in Data.Constraint | |
(Monad m) :=> (Applicative (WrappedMonad m)) | |
Defined in Data.Constraint ins :: Monad m :- Applicative (WrappedMonad m) # | |
Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
(Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0 |
Monad (Tagged s) | |
Class (Monad f, Alternative f) (MonadPlus f) | |
Defined in Data.Constraint | |
Monad ((->) r :: Type -> Type) | Since: base-2.1 |
(Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
Monad (Cokleisli w a) | |
Monad f => Monad (Star f a) | |
Monad (Costar f a) | |
Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
class Applicative f => Alternative (f :: Type -> Type) #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
Instances
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) #
Monads that also support choice and failure.
Instances
MonadPlus [] | Since: base-2.1 |
MonadPlus Maybe | Since: base-2.1 |
MonadPlus IO | Since: base-4.9.0.0 |
MonadPlus ReadP | Since: base-2.1 |
MonadPlus Seq | |
MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
() :=> (MonadPlus []) | |
Defined in Data.Constraint | |
() :=> (MonadPlus Maybe) | |
MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow mzero :: ArrowMonad a a0 # mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # | |
(MonadPlus m) :=> (Alternative (WrappedMonad m)) | |
Defined in Data.Constraint ins :: MonadPlus m :- Alternative (WrappedMonad m) # | |
MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0 |
Class (Monad f, Alternative f) (MonadPlus f) | |
Defined in Data.Constraint | |
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
MonadPlus f => MonadPlus (Star f a) | |
MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
Constraints
class Forall (ComposeC p f) => ForallF (p :: k2 -> Constraint) (f :: k1 -> k2) #
A representation of the quantified constraint forall a. p (f a)
.
Instances
Forall (ComposeC p f) => ForallF (p :: k2 -> Constraint) (f :: k1 -> k2) | |
Defined in Data.Constraint.Forall |
instF :: forall k2 k1 p (f :: k1 -> k2) (a :: k1). ForallF p f :- p (f a) #
Instantiate a quantified
constraint at type ForallF
p fa
.
This is the type of entailment.
a
is read as :-
ba
"entails" b
.
With this we can actually build a category for Constraint
resolution.
e.g.
Because
is a superclass of Eq
a
, we can show that Ord
a
entails Ord
a
.Eq
a
Because instance
exists, we can show that Ord
a => Ord
[a]
entails Ord
a
as well.Ord
[a]
This relationship is captured in the :-
entailment type here.
Since p
and entailment composes, :-
p:-
forms the arrows of a
Category
of constraints. However, Category
only became sufficiently
general to support this instance in GHC 7.8, so prior to 7.8 this instance
is unavailable.
But due to the coherence of instance resolution in Haskell, this Category
has some very interesting properties. Notably, in the absence of
IncoherentInstances
, this category is "thin", which is to say that
between any two objects (constraints) there is at most one distinguishable
arrow.
This means that for instance, even though there are two ways to derive
, the answers from these two paths _must_ by
construction be equal. This is a property that Haskell offers that is
pretty much unique in the space of languages with things they call "type
classes".Ord
a :-
Eq
[a]
What are the two ways?
Well, we can go from
via the
superclass relationship, and then from Ord
a :-
Eq
a
via the
instance, or we can go from Eq
a :-
Eq
[a]
via the instance
then from Ord
a :-
Ord
[a]
through the superclass relationship
and this diagram by definition must "commute".Ord
[a] :-
Eq
[a]
Diagrammatically,
Ord a ins / \ cls v v Ord [a] Eq a cls \ / ins v v Eq [a]
This safety net ensures that pretty much anything you can write with this library is sensible and can't break any assumptions on the behalf of library authors.
Instances
Category (:-) | Possible since GHC 7.8, when |
() :=> (Eq (a :- b)) | |
() :=> (Ord (a :- b)) | |
() :=> (Show (a :- b)) | |
a => HasDict b (a :- b) | |
Defined in Data.Constraint | |
Eq (a :- b) | Assumes |
(Typeable p, Typeable q, p, q) => Data (p :- q) | |
Defined in Data.Constraint gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> (p :- q) -> c (p :- q) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (p :- q) # toConstr :: (p :- q) -> Constr # dataTypeOf :: (p :- q) -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (p :- q)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (p :- q)) # gmapT :: (forall b. Data b => b -> b) -> (p :- q) -> p :- q # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> (p :- q) -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> (p :- q) -> r # gmapQ :: (forall d. Data d => d -> u) -> (p :- q) -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> (p :- q) -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> (p :- q) -> m (p :- q) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> (p :- q) -> m (p :- q) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> (p :- q) -> m (p :- q) # | |
Ord (a :- b) | Assumes |
Defined in Data.Constraint | |
Show (a :- b) | |
a => NFData (a :- b) | |
Defined in Data.Constraint |
Values of type
capture a dictionary for a constraint of type Dict
pp
.
e.g.
Dict
::Dict
(Eq
Int
)
captures a dictionary that proves we have an:
instanceEq
Int
Pattern matching on the Dict
constructor will bring this instance into scope.
Instances
HasDict a (Dict a) | |
Defined in Data.Constraint | |
a :=> (Read (Dict a)) | |
a :=> (Monoid (Dict a)) | |
a :=> (Enum (Dict a)) | |
a :=> (Bounded (Dict a)) | |
() :=> (Eq (Dict a)) | |
() :=> (Ord (Dict a)) | |
() :=> (Show (Dict a)) | |
() :=> (Semigroup (Dict a)) | |
a => Bounded (Dict a) | |
a => Enum (Dict a) | |
Defined in Data.Constraint | |
Eq (Dict a) | |
(Typeable p, p) => Data (Dict p) | |
Defined in Data.Constraint gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Dict p -> c (Dict p) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Dict p) # toConstr :: Dict p -> Constr # dataTypeOf :: Dict p -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Dict p)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Dict p)) # gmapT :: (forall b. Data b => b -> b) -> Dict p -> Dict p # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQ :: (forall d. Data d => d -> u) -> Dict p -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Dict p -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # | |
Ord (Dict a) | |
a => Read (Dict a) | |
Show (Dict a) | |
Semigroup (Dict a) | |
a => Monoid (Dict a) | |
NFData (Dict c) | |
Defined in Data.Constraint |