Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Documentation
class Functor f => Applicative (f :: Type -> Type) where #
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).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
Using ApplicativeDo
: 'fs
' can be understood as
the <*>
asdo
expression
do f <- fs a <- as pure (f a)
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*>
and fmap
.
Using ApplicativeDo
: '
' can be understood
as the liftA2
f as bsdo
expression
do a <- as b <- bs pure (f a b)
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
'as
' can be understood as the *>
bsdo
expression
do as bs
This is a tad complicated for our ApplicativeDo
extension
which will give it a Monad
constraint. For an Applicative
constraint we write it of the form
do _ <- as b <- bs pure b
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Using ApplicativeDo
: 'as
' can be understood as
the <*
bsdo
expression
do a <- as bs pure a
Instances
Applicative [] | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Applicative IO | Since: base-2.1 |
Applicative Min | Since: base-4.9.0.0 |
Applicative Max | Since: base-4.9.0.0 |
Applicative First | Since: base-4.9.0.0 |
Applicative Last | Since: base-4.9.0.0 |
Applicative Option | 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 NonEmpty | Since: base-4.9.0.0 |
Applicative OneOrMore Source # | pure a = OneOrMore a ActuallyNone OneOrMore f fs <*> OneOrMore x xs = OneOrMore (f x) (fs <*> xs) |
Applicative AnyNumberOf Source # | 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 ) = ( 2 ~~ 12 ~~ 9 ~~ ActuallyNone ) This example demonstrates how when there are more arguments than functions,
any excess arguments (in this case, the |
Defined in Acme.Functors pure :: a -> AnyNumberOf a # (<*>) :: AnyNumberOf (a -> b) -> AnyNumberOf a -> AnyNumberOf b # liftA2 :: (a -> b -> c) -> AnyNumberOf a -> AnyNumberOf b -> AnyNumberOf c # (*>) :: AnyNumberOf a -> AnyNumberOf b -> AnyNumberOf b # (<*) :: AnyNumberOf a -> AnyNumberOf b -> AnyNumberOf a # | |
Applicative Two Source # | If you have two functions pure a = Two a a Two f g <*> Two a a' = Two (f a) (g a') |
Applicative OrNot Source # | If you have a function pure = ActuallyYes ActuallyYes f <*> ActuallyYes a = ActuallyYes (f a) _ <*> _ = Nope |
Applicative LiftedButWhy Source # | pure = LiftedButWhy LiftedButWhy f <*> LiftedButWhy a = LiftedButWhy (f a) |
Defined in Acme.Functors pure :: a -> LiftedButWhy a # (<*>) :: LiftedButWhy (a -> b) -> LiftedButWhy a -> LiftedButWhy b # liftA2 :: (a -> b -> c) -> LiftedButWhy a -> LiftedButWhy b -> LiftedButWhy c # (*>) :: LiftedButWhy a -> LiftedButWhy b -> LiftedButWhy b # (<*) :: LiftedButWhy a -> LiftedButWhy b -> LiftedButWhy a # | |
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 # | |
Applicative (DeterminedBy parameter) Source # | pure a = Determination (\_ -> a) Determination f <*> Determination a = Determination (\x -> f x (a x)) |
Defined in Acme.Functors pure :: a -> DeterminedBy parameter a # (<*>) :: DeterminedBy parameter (a -> b) -> DeterminedBy parameter a -> DeterminedBy parameter b # liftA2 :: (a -> b -> c) -> DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter c # (*>) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter b # (<*) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter a # | |
Applicative (OrInsteadFirst otherThing) Source # | pure = NotInsteadFirst NotInsteadFirst f <*> NotInsteadFirst a = NotInsteadFirst (f a) InsteadFirst other <*> _ = InsteadFirst other _ <*> InsteadFirst other = InsteadFirst other |
Defined in Acme.Functors pure :: a -> OrInsteadFirst otherThing a # (<*>) :: OrInsteadFirst otherThing (a -> b) -> OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b # liftA2 :: (a -> b -> c) -> OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b -> OrInsteadFirst otherThing c # (*>) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b -> OrInsteadFirst otherThing b # (<*) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b -> OrInsteadFirst otherThing a # | |
Semigroup otherThing => Applicative (OrInstead otherThing) Source # | 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 |
Defined in Acme.Functors pure :: a -> OrInstead otherThing a # (<*>) :: OrInstead otherThing (a -> b) -> OrInstead otherThing a -> OrInstead otherThing b # liftA2 :: (a -> b -> c) -> OrInstead otherThing a -> OrInstead otherThing b -> OrInstead otherThing c # (*>) :: OrInstead otherThing a -> OrInstead otherThing b -> OrInstead otherThing b # (<*) :: OrInstead otherThing a -> OrInstead otherThing b -> OrInstead otherThing a # | |
Monoid extraThing => Applicative (Also extraThing) Source # | Dragging the pure = (`Also` mempty) (f `Also` extra1) <*> (a `Also` extra2) = f a `Also` (extra1 <> extra2) |
Defined in Acme.Functors pure :: a -> Also extraThing a # (<*>) :: Also extraThing (a -> b) -> Also extraThing a -> Also extraThing b # liftA2 :: (a -> b -> c) -> Also extraThing a -> Also extraThing b -> Also extraThing c # (*>) :: Also extraThing a -> Also extraThing b -> Also extraThing b # (<*) :: Also extraThing a -> Also extraThing b -> Also extraThing a # | |
(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 ((->) r :: Type -> Type) | Since: base-2.1 |
(Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.Base |
class Applicative m => Monad (m :: Type -> Type) 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:
- 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.
(>>=) :: 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.
'as
' can be understood as the >>=
bsdo
expression
do a <- as bs a
(>>) :: 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.
'as
' can be understood as the >>
bsdo
expression
do as bs
Inject a value into the monadic type.
Instances
Monad [] | Since: base-2.1 |
Monad Maybe | Since: base-2.1 |
Monad IO | Since: base-2.1 |
Monad Min | Since: base-4.9.0.0 |
Monad Max | Since: base-4.9.0.0 |
Monad First | Since: base-4.9.0.0 |
Monad Last | Since: base-4.9.0.0 |
Monad Option | Since: base-4.9.0.0 |
Monad NonEmpty | Since: base-4.9.0.0 |
Monad OrNot Source # | |
Monad LiftedButWhy Source # | LiftedButWhy a >>= f = f a |
Defined in Acme.Functors (>>=) :: LiftedButWhy a -> (a -> LiftedButWhy b) -> LiftedButWhy b # (>>) :: LiftedButWhy a -> LiftedButWhy b -> LiftedButWhy b # return :: a -> LiftedButWhy a # | |
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 # | |
Monad (DeterminedBy parameter) Source # | Determination fa >>= ff = Determination (\x -> let Determination f = ff (fa x) in f x) |
Defined in Acme.Functors (>>=) :: DeterminedBy parameter a -> (a -> DeterminedBy parameter b) -> DeterminedBy parameter b # (>>) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter b # return :: a -> DeterminedBy parameter a # | |
Monad (OrInsteadFirst otherThing) Source # | InsteadFirst other >>= _ = InsteadFirst other NotInsteadFirst a >>= f = f a |
Defined in Acme.Functors (>>=) :: OrInsteadFirst otherThing a -> (a -> OrInsteadFirst otherThing b) -> OrInsteadFirst otherThing b # (>>) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b -> OrInsteadFirst otherThing b # return :: a -> OrInsteadFirst otherThing a # | |
(Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
Monad ((->) r :: Type -> Type) | Since: base-2.1 |
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
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
.
The Haskell Report defines no laws for Eq
. However, ==
is customarily
expected to implement an equivalence relationship where two values comparing
equal are indistinguishable by "public" functions, with a "public" function
being one not allowing to see implementation details. For example, for a
type representing non-normalised natural numbers modulo 100, a "public"
function doesn't make the difference between 1 and 201. It is expected to
have the following properties:
Instances
Eq Bool | |
Eq Char | |
Eq Double | Note that due to the presence of
Also note that
|
Eq Float | Note that due to the presence of
Also note that
|
Eq Int | |
Eq Integer | |
Eq Natural | Since: base-4.8.0.0 |
Eq Ordering | |
Eq Word | |
Eq () | |
Eq TyCon | |
Eq Module | |
Eq TrName | |
Eq SrcLoc | Since: base-4.9.0.0 |
Eq BigNat | |
Eq a => Eq [a] | |
Eq a => Eq (Maybe a) | Since: base-2.1 |
Eq a => Eq (Ratio a) | Since: base-2.1 |
Eq a => Eq (Min a) | Since: base-4.9.0.0 |
Eq a => Eq (Max a) | Since: base-4.9.0.0 |
Eq a => Eq (First a) | Since: base-4.9.0.0 |
Eq a => Eq (Last a) | Since: base-4.9.0.0 |
Eq m => Eq (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup (==) :: WrappedMonoid m -> WrappedMonoid m -> Bool # (/=) :: WrappedMonoid m -> WrappedMonoid m -> Bool # | |
Eq a => Eq (Option a) | Since: base-4.9.0.0 |
Eq a => Eq (ZipList a) | Since: base-4.7.0.0 |
Eq a => Eq (NonEmpty a) | Since: base-4.9.0.0 |
Eq a => Eq (OneOrMore a) Source # | |
Eq a => Eq (AnyNumberOf a) Source # | |
Defined in Acme.Functors (==) :: AnyNumberOf a -> AnyNumberOf a -> Bool # (/=) :: AnyNumberOf a -> AnyNumberOf a -> Bool # | |
Eq a => Eq (Two a) Source # | |
Eq a => Eq (OrNot a) Source # | |
Eq a => Eq (LiftedButWhy a) Source # | |
Defined in Acme.Functors (==) :: LiftedButWhy a -> LiftedButWhy a -> Bool # (/=) :: LiftedButWhy a -> LiftedButWhy a -> Bool # | |
(Eq a, Eq b) => Eq (a, b) | |
Eq a => Eq (Arg a b) | Since: base-4.9.0.0 |
(Eq a, Eq otherThing) => Eq (OrInsteadFirst otherThing a) Source # | |
Defined in Acme.Functors (==) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing a -> Bool # (/=) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing a -> Bool # | |
(Eq a, Eq otherThing) => Eq (OrInstead otherThing a) Source # | |
(Eq a, Eq extraThing) => Eq (Also extraThing a) Source # | |
(Eq a, Eq b, Eq c) => Eq (a, b, c) | |
(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) | |
class Functor (f :: Type -> Type) where #
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.
fmap :: (a -> b) -> f a -> f b #
Using ApplicativeDo
: '
' can be understood as
the fmap
f asdo
expression
do a <- as pure (f a)
with an inferred Functor
constraint.
Instances
Functor [] | Since: base-2.1 |
Functor Maybe | Since: base-2.1 |
Functor IO | Since: base-2.1 |
Functor Min | Since: base-4.9.0.0 |
Functor Max | Since: base-4.9.0.0 |
Functor First | Since: base-4.9.0.0 |
Functor Last | Since: base-4.9.0.0 |
Functor Option | Since: base-4.9.0.0 |
Functor ZipList | Since: base-2.1 |
Functor NonEmpty | Since: base-4.9.0.0 |
Functor OneOrMore Source # | |
Functor AnyNumberOf Source # | |
Defined in Acme.Functors fmap :: (a -> b) -> AnyNumberOf a -> AnyNumberOf b # (<$) :: a -> AnyNumberOf b -> AnyNumberOf a # | |
Functor Two Source # | |
Functor OrNot Source # | |
Functor LiftedButWhy Source # | |
Defined in Acme.Functors fmap :: (a -> b) -> LiftedButWhy a -> LiftedButWhy b # (<$) :: a -> LiftedButWhy b -> LiftedButWhy a # | |
Functor ((,) a) | Since: base-2.1 |
Functor (Arg a) | Since: base-4.9.0.0 |
Monad m => Functor (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a # | |
Functor (DeterminedBy parameter) Source # | |
Defined in Acme.Functors fmap :: (a -> b) -> DeterminedBy parameter a -> DeterminedBy parameter b # (<$) :: a -> DeterminedBy parameter b -> DeterminedBy parameter a # | |
Functor (OrInsteadFirst otherThing) Source # | |
Defined in Acme.Functors fmap :: (a -> b) -> OrInsteadFirst otherThing a -> OrInsteadFirst otherThing b # (<$) :: a -> OrInsteadFirst otherThing b -> OrInsteadFirst otherThing a # | |
Functor (OrInstead otherThing) Source # | |
Functor (Also extraThing) Source # | |
Functor ((,,) a b) | Since: base-4.14.0.0 |
Arrow a => Functor (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Functor ((->) r :: Type -> Type) | Since: base-2.1 |
Functor ((,,,) a b c) | Since: base-4.14.0.0 |
class Semigroup a => Monoid a where Source #
Instances
Monoid a => Monoid (OneOrMore a) Source # | mempty = OneOrMore mempty ActuallyNone |
Defined in Acme.Functors | |
Monoid a => Monoid (AnyNumberOf a) Source # | mempty = mempty ~~ mempty |
Defined in Acme.Functors mempty :: AnyNumberOf a Source # | |
Monoid a => Monoid (Two a) Source # | mempty = Two mempty mempty |
Defined in Acme.Functors | |
Monoid a => Monoid (OrNot a) Source # | mempty = ActuallyYes mempty |
Defined in Acme.Functors | |
Monoid a => Monoid (LiftedButWhy a) Source # | mempty = LiftedButWhy mempty |
Defined in Acme.Functors mempty :: LiftedButWhy a Source # | |
Monoid a => Monoid (DeterminedBy parameter a) Source # | mempty = Determination (\_ -> mempty) |
Defined in Acme.Functors mempty :: DeterminedBy parameter a Source # | |
(Semigroup otherThing, Monoid a) => Monoid (OrInsteadFirst otherThing a) Source # | mempty = NotInsteadFirst mempty |
Defined in Acme.Functors mempty :: OrInsteadFirst otherThing a Source # | |
(Semigroup otherThing, Monoid a) => Monoid (OrInstead otherThing a) Source # | |
Defined in Acme.Functors | |
(Monoid extraThing, Monoid a) => Monoid (Also extraThing a) Source # | mempty = Also mempty mempty |
Defined in Acme.Functors |
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
Since: base-4.9.0.0
(<>) :: a -> a -> a infixr 6 #
An associative operation.
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
>>>
import Data.List.NonEmpty
>>>
sconcat $ "Hello" :| [" ", "Haskell", "!"]
"Hello Haskell!"
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 \(\mathcal{O}(1)\) by
picking stimes =
or stimesIdempotent
stimes =
respectively.stimesIdempotentMonoid
>>>
stimes 4 [1]
[1,1,1,1]
Instances
Semigroup Ordering | Since: base-4.9.0.0 |
Semigroup () | Since: base-4.9.0.0 |
Semigroup [a] | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (IO a) | Since: base-4.10.0.0 |
Ord a => Semigroup (Min a) | Since: base-4.9.0.0 |
Ord a => Semigroup (Max a) | Since: base-4.9.0.0 |
Semigroup (First a) | Since: base-4.9.0.0 |
Semigroup (Last a) | Since: base-4.9.0.0 |
Monoid m => Semigroup (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m # | |
Semigroup a => Semigroup (Option a) | Since: base-4.9.0.0 |
Semigroup (NonEmpty a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (OneOrMore a) Source # | OneOrMore a more <> OneOrMore a' more' = OneOrMore a (more <> OneAndMaybeMore a' more') |
Semigroup a => Semigroup (AnyNumberOf a) Source # | The operation of combining some number of OneAndMaybeMore x xs <> OneAndMaybeMore y ys = OneAndMaybeMore (x <> y) (xs <> ys) _ <> _ = ActuallyNone |
Defined in Acme.Functors (<>) :: AnyNumberOf a -> AnyNumberOf a -> AnyNumberOf a # sconcat :: NonEmpty (AnyNumberOf a) -> AnyNumberOf a # stimes :: Integral b => b -> AnyNumberOf a -> AnyNumberOf a # | |
Semigroup a => Semigroup (Two a) Source # | Two x y <> Two x' y' = Two (x <> x') (y <> y') |
Semigroup a => Semigroup (OrNot a) Source # | If you have value ActuallyYes a <> ActuallyYes a' = ActuallyYes (a <> a') _ <> _ = Nope |
Semigroup a => Semigroup (LiftedButWhy a) Source # | LiftedButWhy x <> LiftedButWhy y = LiftedButWhy (x <> y) |
Defined in Acme.Functors (<>) :: LiftedButWhy a -> LiftedButWhy a -> LiftedButWhy a # sconcat :: NonEmpty (LiftedButWhy a) -> LiftedButWhy a # stimes :: Integral b => b -> LiftedButWhy a -> LiftedButWhy a # | |
Semigroup b => Semigroup (a -> b) | Since: base-4.9.0.0 |
(Semigroup a, Semigroup b) => Semigroup (a, b) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (DeterminedBy parameter a) Source # | Determination f <> Determination g = Determination (\x -> f x <> g x) |
Defined in Acme.Functors (<>) :: DeterminedBy parameter a -> DeterminedBy parameter a -> DeterminedBy parameter a # sconcat :: NonEmpty (DeterminedBy parameter a) -> DeterminedBy parameter a # stimes :: Integral b => b -> DeterminedBy parameter a -> DeterminedBy parameter a # | |
(Semigroup otherThing, Semigroup a) => Semigroup (OrInsteadFirst otherThing a) Source # | NotInsteadFirst a <> NotInsteadFirst a' = NotInsteadFirst (a <> a') InsteadFirst other <> _ = InsteadFirst other _ <> InsteadFirst other = InsteadFirst other |
Defined in Acme.Functors (<>) :: OrInsteadFirst otherThing a -> OrInsteadFirst otherThing a -> OrInsteadFirst otherThing a # sconcat :: NonEmpty (OrInsteadFirst otherThing a) -> OrInsteadFirst otherThing a # stimes :: Integral b => b -> OrInsteadFirst otherThing a -> OrInsteadFirst otherThing a # | |
(Semigroup otherThing, Semigroup a) => Semigroup (OrInstead otherThing a) Source # | 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) Source # | (a `Also` extra1) <> (a' `Also` extra2) = (a <> a') `Also` (extra1 <> extra2) |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: base-4.9.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | Since: base-4.9.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) | Since: base-4.9.0.0 |
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)"
.
:: Int | the operator precedence of the enclosing
context (a number from |
-> a | the value to be converted to 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.
Instances
Show Bool | Since: base-2.1 |
Show Char | Since: base-2.1 |
Show Int | Since: base-2.1 |
Show Integer | Since: base-2.1 |
Show Natural | Since: base-4.8.0.0 |
Show Ordering | Since: base-2.1 |
Show Word | Since: base-2.1 |
Show RuntimeRep | Since: base-4.11.0.0 |
Defined in GHC.Show showsPrec :: Int -> RuntimeRep -> ShowS # show :: RuntimeRep -> String # showList :: [RuntimeRep] -> ShowS # | |
Show VecCount | Since: base-4.11.0.0 |
Show VecElem | Since: base-4.11.0.0 |
Show CallStack | Since: base-4.9.0.0 |
Show () | Since: base-2.1 |
Show TyCon | Since: base-2.1 |
Show Module | Since: base-4.9.0.0 |
Show TrName | Since: base-4.9.0.0 |
Show KindRep | |
Show TypeLitSort | Since: base-4.11.0.0 |
Defined in GHC.Show showsPrec :: Int -> TypeLitSort -> ShowS # show :: TypeLitSort -> String # showList :: [TypeLitSort] -> ShowS # | |
Show SrcLoc | Since: base-4.9.0.0 |
Show a => Show [a] | Since: base-2.1 |
Show a => Show (Maybe a) | Since: base-2.1 |
Show a => Show (Ratio a) | Since: base-2.0.1 |
Show a => Show (Min a) | Since: base-4.9.0.0 |
Show a => Show (Max a) | Since: base-4.9.0.0 |
Show a => Show (First a) | Since: base-4.9.0.0 |
Show a => Show (Last a) | Since: base-4.9.0.0 |
Show m => Show (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup showsPrec :: Int -> WrappedMonoid m -> ShowS # show :: WrappedMonoid m -> String # showList :: [WrappedMonoid m] -> ShowS # | |
Show a => Show (Option a) | Since: base-4.9.0.0 |
Show a => Show (ZipList a) | Since: base-4.7.0.0 |
Show a => Show (NonEmpty a) | Since: base-4.11.0.0 |
Show a => Show (OneOrMore a) Source # | |
Show a => Show (AnyNumberOf a) Source # | |
Defined in Acme.Functors showsPrec :: Int -> AnyNumberOf a -> ShowS # show :: AnyNumberOf a -> String # showList :: [AnyNumberOf a] -> ShowS # | |
Show a => Show (Two a) Source # | |
Show a => Show (OrNot a) Source # | |
Show a => Show (LiftedButWhy a) Source # | |
Defined in Acme.Functors showsPrec :: Int -> LiftedButWhy a -> ShowS # show :: LiftedButWhy a -> String # showList :: [LiftedButWhy a] -> ShowS # | |
(Show a, Show b) => Show (a, b) | Since: base-2.1 |
(Show a, Show b) => Show (Arg a b) | Since: base-4.9.0.0 |
(Show a, Show otherThing) => Show (OrInsteadFirst otherThing a) Source # | |
Defined in Acme.Functors showsPrec :: Int -> OrInsteadFirst otherThing a -> ShowS # show :: OrInsteadFirst otherThing a -> String # showList :: [OrInsteadFirst otherThing a] -> ShowS # | |
(Show a, Show otherThing) => Show (OrInstead otherThing a) Source # | |
(Show a, Show extraThing) => Show (Also extraThing a) Source # | |
(Show a, Show b, Show c) => Show (a, b, c) | Since: base-2.1 |
(Show a, Show b, Show c, Show d) => Show (a, b, c, d) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 |