Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- class Functor f => Applicative f where
- class Applicative m => Monad m where
- class Eq a where
- class Functor f where
- class Semigroup a => Monoid a where
- class Semigroup a where
- class Show a where
Documentation
class Functor f => Applicative f where #
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
- 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
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Applicative [] | |
Applicative Maybe | |
Applicative IO | |
Applicative U1 | |
Applicative Par1 | |
Applicative Min | |
Applicative Max | |
Applicative First | |
Applicative Last | |
Applicative Option | |
Applicative NonEmpty | |
Applicative ZipList | |
Applicative Dual | |
Applicative Sum | |
Applicative Product | |
Applicative First | |
Applicative Last | |
Applicative OneOrMore # | pure a = OneOrMore a ActuallyNone OneOrMore f fs <*> OneOrMore x xs = OneOrMore (f x) (fs <*> xs) |
Applicative AnyNumberOf # | You can use this to apply any number of functions to any number of arguments. pure a = OneAndMaybeMore a ActuallyNone OneAndMaybeMore f fs <*> OneAndMaybeMore x xs = OneAndMaybeMore (f x) (fs <*> xs) _ <*> _ = ActuallyNone Example: ( (+ 1) ~~ (* 2) ~~ (+ 5) ~~ ActuallyNone ) <*> ( 1 ~~ 6 ~~ 4 ~~ 37 ~~ ActuallyNone ) = ( 7 ~~ 12 ~~ 9 ~~ ActuallyNone ) This example demonstrates how when there are more arguments than functions,
any excess arguments (in this case, the |
Applicative Two # | If you have two functions pure a = Two a a Two f g <*> Two a a' = Two (f a) (g a') |
Applicative OrNot # | If you have a function pure = ActuallyYes ActuallyYes f <*> ActuallyYes a = ActuallyYes (f a) _ <*> _ = Nope |
Applicative LiftedButWhy # | pure = LiftedButWhy LiftedButWhy f <*> LiftedButWhy a = LiftedButWhy (f a) |
Applicative ((->) a) | |
Applicative (Either e) | |
Applicative f => Applicative (Rec1 f) | |
Monoid a => Applicative ((,) a) | |
Monad m => Applicative (WrappedMonad m) | |
Applicative (DeterminedBy parameter) # | pure a = Determination (\_ -> a) Determination f <*> Determination a = Determination (\x -> f x (a x)) |
Applicative (OrInsteadFirst otherThing) # | pure = NotInsteadFirst NotInsteadFirst f <*> NotInsteadFirst a = NotInsteadFirst (f a) InsteadFirst other <*> _ = InsteadFirst other _ <*> InsteadFirst other = InsteadFirst other |
Semigroup otherThing => Applicative (OrInstead otherThing) # | The possibility of having an pure = NotInstead NotInstead f <*> NotInstead a = NotInstead (f a) Instead other1 <*> Instead other2 = Instead (other1 <> other2) Instead other <*> _ = Instead other _ <*> Instead other = Instead other |
Monoid extraThing => Applicative (Also extraThing) # | Dragging the pure = (`Also` mempty) (f `Also` extra1) <*> (a `Also` extra2) = f a `Also` (extra1 <> extra2) |
(Applicative f, Applicative g) => Applicative ((:*:) f g) | |
(Applicative f, Applicative g) => Applicative ((:.:) f g) | |
Arrow a => Applicative (WrappedArrow a b) | |
Monoid m => Applicative (Const * m) | |
Applicative f => Applicative (Alt * f) | |
Applicative f => Applicative (M1 i c f) | |
class Applicative m => Monad m where #
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 laws:
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.
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
Fail with a message. This operation is not part of the
mathematical definition of a monad, but is invoked on pattern-match
failure in a do
expression.
As part of the MonadFail proposal (MFP), this function is moved
to its own class MonadFail
(see Control.Monad.Fail for more
details). The definition here will be removed in a future
release.
Monad [] | |
Monad Maybe | |
Monad IO | |
Monad U1 | |
Monad Par1 | |
Monad Min | |
Monad Max | |
Monad First | |
Monad Last | |
Monad Option | |
Monad NonEmpty | |
Monad Dual | |
Monad Sum | |
Monad Product | |
Monad First | |
Monad Last | |
Monad OrNot # | |
Monad LiftedButWhy # | LiftedButWhy a >>= f = f a |
Monad ((->) r) | |
Monad (Either e) | |
Monad f => Monad (Rec1 f) | |
Monoid a => Monad ((,) a) | |
Monad m => Monad (WrappedMonad m) | |
Monad (Proxy *) | |
Monad (DeterminedBy parameter) # | Determination fa >>= ff = Determination (\x -> let Determination f = ff (fa x) in f x) |
Monad (OrInsteadFirst otherThing) # | InsteadFirst other >>= _ = InsteadFirst other NotInsteadFirst a >>= f = f a |
(Monad f, Monad g) => Monad ((:*:) f g) | |
Monad f => Monad (Alt * f) | |
Monad f => Monad (M1 i c f) | |
The Eq
class defines equality (==
) and inequality (/=
).
All the basic datatypes exported by the Prelude are instances of Eq
,
and Eq
may be derived for any datatype whose constituents are also
instances of Eq
.
Eq Bool | |
Eq Char | |
Eq Double | |
Eq Float | |
Eq Int | |
Eq Integer | |
Eq Ordering | |
Eq Word | |
Eq () | |
Eq TyCon | |
Eq BigNat | |
Eq SpecConstrAnnotation | |
Eq Void | |
Eq Version | |
Eq AsyncException | |
Eq ArrayException | |
Eq ExitCode | |
Eq IOErrorType | |
Eq All | |
Eq Any | |
Eq Fixity | |
Eq Associativity | |
Eq SourceUnpackedness | |
Eq SourceStrictness | |
Eq DecidedStrictness | |
Eq MaskingState | |
Eq IOException | |
Eq ErrorCall | |
Eq ArithException | |
Eq SomeNat | |
Eq SomeSymbol | |
Eq SrcLoc | |
Eq a => Eq [a] | |
Eq a => Eq (Maybe a) | |
Eq a => Eq (Ratio a) | |
Eq (Ptr a) | |
Eq (FunPtr a) | |
Eq (V1 p) | |
Eq (U1 p) | |
Eq p => Eq (Par1 p) | |
Eq a => Eq (Min a) | |
Eq a => Eq (Max a) | |
Eq a => Eq (First a) | |
Eq a => Eq (Last a) | |
Eq m => Eq (WrappedMonoid m) | |
Eq a => Eq (Option a) | |
Eq a => Eq (NonEmpty a) | |
Eq a => Eq (ZipList a) | |
Eq a => Eq (Dual a) | |
Eq a => Eq (Sum a) | |
Eq a => Eq (Product a) | |
Eq a => Eq (First a) | |
Eq a => Eq (Last a) | |
Eq a => Eq (OneOrMore a) # | |
Eq a => Eq (AnyNumberOf a) # | |
Eq a => Eq (Two a) # | |
Eq a => Eq (OrNot a) # | |
Eq a => Eq (LiftedButWhy a) # | |
(Eq b, Eq a) => Eq (Either a b) | |
Eq (f p) => Eq (Rec1 f p) | |
Eq (URec Char p) | |
Eq (URec Double p) | |
Eq (URec Float p) | |
Eq (URec Int p) | |
Eq (URec Word p) | |
Eq (URec (Ptr ()) p) | |
(Eq a, Eq b) => Eq (a, b) | |
Eq a => Eq (Arg a b) | |
Eq (Proxy k s) | |
(Eq otherThing, Eq a) => Eq (OrInsteadFirst otherThing a) # | |
(Eq otherThing, Eq a) => Eq (OrInstead otherThing a) # | |
(Eq extraThing, Eq a) => Eq (Also extraThing a) # | |
Eq c => Eq (K1 i c p) | |
(Eq (g p), Eq (f p)) => Eq ((:+:) f g p) | |
(Eq (g p), Eq (f p)) => Eq ((:*:) f g p) | |
Eq (f (g p)) => Eq ((:.:) f g p) | |
(Eq a, Eq b, Eq c) => Eq (a, b, c) | |
Eq a => Eq (Const k a b) | |
Eq (f a) => Eq (Alt k f a) | |
Eq ((:~:) k a b) | |
Eq (f p) => Eq (M1 i c f p) | |
(Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) | |
(Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
(Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
The Functor
class is used for types that can be mapped over.
Instances of Functor
should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor
for lists, Maybe
and IO
satisfy these laws.
class Semigroup a => Monoid a where Source #
Monoid a => Monoid (OneOrMore a) Source # | mempty = OneOrMore mempty ActuallyNone |
Monoid a => Monoid (AnyNumberOf a) Source # | mempty = mempty ~~ mempty |
Monoid a => Monoid (Two a) Source # | mempty = Two mempty mempty |
Monoid a => Monoid (OrNot a) Source # | mempty = ActuallyYes mempty |
Monoid a => Monoid (LiftedButWhy a) Source # | mempty = LiftedButWhy mempty |
Monoid a => Monoid (DeterminedBy parameter a) Source # | mempty = Determination (\_ -> mempty) |
(Semigroup otherThing, Monoid a) => Monoid (OrInsteadFirst otherThing a) Source # | mempty = NotInsteadFirst mempty |
(Semigroup otherThing, Monoid a) => Monoid (OrInstead otherThing a) Source # | |
(Monoid extraThing, Monoid a) => Monoid (Also extraThing a) Source # | mempty = Also mempty mempty |
The class of semigroups (types with an associative binary operation).
Since: 4.9.0.0
(<>) :: a -> a -> a infixr 6 #
An associative operation.
(a<>
b)<>
c = a<>
(b<>
c)
If a
is also a Monoid
we further require
(<>
) =mappend
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
stimes :: Integral b => b -> a -> a #
Repeat a value n
times.
Given that this works on a Semigroup
it is allowed to fail if
you request 0 or fewer repetitions, and the default definition
will do so.
By making this a member of the class, idempotent semigroups and monoids can
upgrade this to execute in O(1) by picking
stimes = stimesIdempotent
or stimes = stimesIdempotentMonoid
respectively.
Semigroup Ordering | |
Semigroup () | |
Semigroup Void | |
Semigroup All | |
Semigroup Any | |
Semigroup [a] | |
Semigroup a => Semigroup (Maybe a) | |
Ord a => Semigroup (Min a) | |
Ord a => Semigroup (Max a) | |
Semigroup (First a) | |
Semigroup (Last a) | |
Monoid m => Semigroup (WrappedMonoid m) | |
Semigroup a => Semigroup (Option a) | |
Semigroup (NonEmpty a) | |
Semigroup a => Semigroup (Dual a) | |
Semigroup (Endo a) | |
Num a => Semigroup (Sum a) | |
Num a => Semigroup (Product a) | |
Semigroup (First a) | |
Semigroup (Last a) | |
Semigroup a => Semigroup (OneOrMore a) # | OneOrMore a more <> OneOrMore a' more' = OneOrMore a (more <> OneAndMaybeMore a' more') |
Semigroup a => Semigroup (AnyNumberOf a) # | The operation of combining some number of OneAndMaybeMore x xs <> OneAndMaybeMore y ys = OneAndMaybeMore (x <> y) (xs <> ys) _ <> _ = ActuallyNone |
Semigroup a => Semigroup (Two a) # | Two x y <> Two x' y' = Two (x <> x') (y <> y') |
Semigroup a => Semigroup (OrNot a) # | If you have value ActuallyYes a <> ActuallyYes a' = ActuallyYes (a <> a') _ <> _ = Nope |
Semigroup a => Semigroup (LiftedButWhy a) # | LiftedButWhy x <> LiftedButWhy y = LiftedButWhy (x <> y) |
Semigroup b => Semigroup (a -> b) | |
Semigroup (Either a b) | |
(Semigroup a, Semigroup b) => Semigroup (a, b) | |
Semigroup (Proxy k s) | |
Semigroup a => Semigroup (DeterminedBy parameter a) # | Determination f <> Determination g = Determination (\x -> f x <> g x) |
(Semigroup otherThing, Semigroup a) => Semigroup (OrInsteadFirst otherThing a) # | NotInsteadFirst a <> NotInsteadFirst a' = NotInsteadFirst (a <> a') InsteadFirst other <> _ = InsteadFirst other _ <> InsteadFirst other = InsteadFirst other |
(Semigroup otherThing, Semigroup a) => Semigroup (OrInstead otherThing a) # | NotInstead a <> NotInstead a' = NotInstead (a <> a') Instead other1 <> Instead other2 = Instead (other1 <> other2) Instead other <> _ = Instead other _ <> Instead other = Instead other |
(Semigroup extraThing, Semigroup a) => Semigroup (Also extraThing a) # | (a `Also` extra1) <> (a' `Also` extra2) = (a <> a') `Also` (extra1 <> extra2) |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | |
Semigroup a => Semigroup (Const k a b) | |
Alternative f => Semigroup (Alt * f a) | |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) | |
Conversion of values to readable String
s.
Derived instances of Show
have the following properties, which
are compatible with derived instances of Read
:
- The result of
show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrec
will produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
show
will produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show
is equivalent to
instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5
Note that right-associativity of :^:
is ignored. For example,
produces the stringshow
(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"
.
showsPrec :: Int -> a -> ShowS #
Convert a value to a readable String
.
showsPrec
should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
Derived instances of Read
and Show
satisfy the following:
That is, readsPrec
parses the string produced by
showsPrec
, and delivers the value that showsPrec
started with.