Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

A collection of common operators provided across various modules of the "base" package.

## Synopsis

- (*>) :: Applicative f => f a -> f b -> f b
- (<*) :: Applicative f => f a -> f b -> f a
- (<*>) :: Applicative f => f (a -> b) -> f a -> f b
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- (<|>) :: Alternative f => f a -> f a -> f a
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (>>) :: Monad m => m a -> m b -> m b
- (>>=) :: Monad m => m a -> (a -> m b) -> m b
- (.&.) :: Bits a => a -> a -> a
- (.|.) :: Bits a => a -> a -> a
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- (/=) :: Eq a => a -> a -> Bool
- (==) :: Eq a => a -> a -> Bool
- ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
- (&) :: a -> (a -> b) -> b
- (.) :: (b -> c) -> (a -> b) -> a -> c
- ($>) :: Functor f => f a -> b -> f b
- (<$) :: Functor f => a -> f b -> f a
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- (>$) :: Contravariant f => b -> f b -> f a
- (>$<) :: Contravariant f => (a -> b) -> f b -> f a
- (>$$<) :: Contravariant f => f b -> (a -> b) -> f a
- ($<) :: Contravariant f => f b -> b -> f a
- (<) :: Ord a => a -> a -> Bool
- (<=) :: Ord a => a -> a -> Bool
- (>) :: Ord a => a -> a -> Bool
- (>=) :: Ord a => a -> a -> Bool
- (%) :: Integral a => a -> a -> Ratio a
- (<>) :: Semigroup a => a -> a -> a
- ($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
- (*) :: Num a => a -> a -> a
- (+) :: Num a => a -> a -> a
- (-) :: Num a => a -> a -> a
- (/) :: Fractional a => a -> a -> a
- (^) :: (Num a, Integral b) => a -> b -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a

# From Control.Applicative

(*>) :: Applicative f => f a -> f b -> f b infixl 4 Source #

Sequence actions, discarding the value of the first argument.

'`as `

' can be understood as the `*>`

bs`do`

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

(<*) :: Applicative f => f a -> f b -> f a infixl 4 Source #

Sequence actions, discarding the value of the second argument.

Using `ApplicativeDo`

: '`as `

' can be understood as
the `<*`

bs`do`

expression

do a <- as bs pure a

(<*>) :: Applicative f => f (a -> b) -> f a -> f b infixl 4 Source #

(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 Source #

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 Source #

An associative binary operation

# From Control.Monad

(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 Source #

Same as `>>=`

, but with the arguments interchanged.

(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 Source #

Left-to-right composition of Kleisli arrows.

'`(bs `

' can be understood as the `>=>`

cs) a`do`

expression

do b <- bs a cs b

(>>) :: Monad m => m a -> m b -> m b infixl 1 Source #

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 `>>`

bs`do`

expression

do as bs

(>>=) :: Monad m => m a -> (a -> m b) -> m b infixl 1 Source #

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

'`as `

' can be understood as the `>>=`

bs`do`

expression

do a <- as bs a

# From Data.Bits

# From Data.Bool

# From Data.Function

($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 Source #

Application operator. This operator is redundant, since ordinary
application `(f x)`

means the same as `(f `

. However, `$`

x)`$`

has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:

f $ g $ h x = f (g (h x))

It is also useful in higher-order situations, such as

,
or `map`

(`$`

0) xs

.`zipWith`

(`$`

) fs xs

Note that `(`

is levity-polymorphic in its result type, so that
`$`

)`foo `

where `$`

True`foo :: Bool -> Int#`

is well-typed.

# From Data.Functor

($>) :: Functor f => f a -> b -> f b infixl 4 Source #

Flipped version of `<$`

.

Using `ApplicativeDo`

: '`as `

' can be understood as the
`$>`

b`do`

expression

do as pure b

with an inferred `Functor`

constraint.

#### Examples

Replace the contents of a

with a constant
`Maybe`

`Int`

`String`

:

`>>>`

Nothing`Nothing $> "foo"`

`>>>`

Just "foo"`Just 90210 $> "foo"`

Replace the contents of an

with a constant `Either`

`Int`

`Int`

`String`

, resulting in an

:`Either`

`Int`

`String`

`>>>`

Left 8675309`Left 8675309 $> "foo"`

`>>>`

Right "foo"`Right 8675309 $> "foo"`

Replace each element of a list with a constant `String`

:

`>>>`

["foo","foo","foo"]`[1,2,3] $> "foo"`

Replace the second element of a pair with a constant `String`

:

`>>>`

(1,"foo")`(1,2) $> "foo"`

*Since: base-4.7.0.0*

(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 Source #

An infix synonym for `fmap`

.

The name of this operator is an allusion to `$`

.
Note the similarities between their types:

($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas `$`

is function application, `<$>`

is function
application lifted over a `Functor`

.

#### Examples

Convert from a

to a `Maybe`

`Int`

using `Maybe`

`String`

`show`

:

`>>>`

Nothing`show <$> Nothing`

`>>>`

Just "3"`show <$> Just 3`

Convert from an

to an
`Either`

`Int`

`Int`

`Either`

`Int`

`String`

using `show`

:

`>>>`

Left 17`show <$> Left 17`

`>>>`

Right "17"`show <$> Right 17`

Double each element of a list:

`>>>`

[2,4,6]`(*2) <$> [1,2,3]`

Apply `even`

to the second element of a pair:

`>>>`

(2,True)`even <$> (2,2)`

# From Data.Functor.Contravariant

(>$) :: Contravariant f => b -> f b -> f a infixl 4 Source #

(>$<) :: Contravariant f => (a -> b) -> f b -> f a infixl 4 Source #

This is an infix alias for `contramap`

.

(>$$<) :: Contravariant f => f b -> (a -> b) -> f a infixl 4 Source #

This is an infix version of `contramap`

with the arguments flipped.

($<) :: Contravariant f => f b -> b -> f a infixl 4 Source #

This is `>$`

with its arguments flipped.

# From Data.Ord

# From Data.Ratio

# From Data.Semigroup

(<>) :: Semigroup a => a -> a -> a infixr 6 Source #

An associative operation.

`>>>`

[1,2,3,4,5,6]`[1,2,3] <> [4,5,6]`

# From Prelude

($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 Source #

Strict (call-by-value) application operator. It takes a function and an argument, evaluates the argument to weak head normal form (WHNF), then calls the function with that value.

(/) :: Fractional a => a -> a -> a infixl 7 Source #

Fractional division.

(^) :: (Num a, Integral b) => a -> b -> a infixr 8 Source #

raise a number to a non-negative integral power

(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 Source #

raise a number to an integral power