streaming-0.2.3.1: an elementary streaming prelude and general stream type.
Safe Haskell Safe-Inferred
Language Haskell2010

Streaming

Synopsis

An iterable streaming monad transformer

The Stream data type can be used to represent any effectful succession of steps arising in some monad. The form of the steps is specified by the first ("functor") parameter in Stream f m r . The monad of the underlying effects is expressed by the second parameter.

This module exports combinators that pertain to that general case. Some of these are quite abstract and pervade any use of the library, e.g.

  maps    :: (forall x . f x -> g x)     -> Stream f m r -> Stream g m r
  mapped  :: (forall x . f x -> m (g x)) -> Stream f m r -> Stream g m r
  hoist   :: (forall x . m x -> n x)     -> Stream f m r -> Stream f n r -- from the MFunctor instance
  concats :: Stream (Stream f m) m r     -> Stream f m r

(assuming here and thoughout that m or n satisfies a Monad constraint, and f or g a Functor constraint.)

Others are surprisingly determinate in content:

  chunksOf     :: Int -> Stream f m r -> Stream (Stream f m) m r
  splitsAt     :: Int -> Stream f m r -> Stream f m (Stream f m r)
  zipsWith     :: (forall x y. f x -> g y -> h (x, y))
               -> Stream f m r -> Stream g m r -> Stream h m r
  zipsWith'    :: (forall x y p. (x -> y -> p) -> f x -> g y -> h p)
               -> Stream f m r -> Stream g m r -> Stream h m r
  intercalates :: Stream f m () -> Stream (Stream f m) m r -> Stream f m r
  unzips       :: Stream (Compose f g) m r ->  Stream f (Stream g m) r
  separate     :: Stream (Sum f g) m r -> Stream f (Stream g m) r  -- cp. partitionEithers
  unseparate   :: Stream f (Stream g) m r -> Stream (Sum f g) m r
  groups       :: Stream (Sum f g) m r -> Stream (Sum (Stream f m) (Stream g m)) m r

One way to see that any streaming library needs some such general type is that it is required to represent the segmentation of a stream, and to express the equivalents of Prelude/Data.List combinators that involve 'lists of lists' and the like. See for example this post on the correct expression of a streaming 'lines' function.

The module Streaming.Prelude exports combinators relating to

Stream (Of a) m r

where Of a r = !a :> r is a left-strict pair.

This expresses the concept of a Producer or Source or Generator and easily inter-operates with types with such names in e.g. conduit , iostreams and pipes .

data Stream f m r Source #

Instances

Instances details
( Functor f, MonadState s m) => MonadState s ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Functor f, MonadReader r m) => MonadReader r ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Functor f, MonadError e m) => MonadError e ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

Functor f => MMonad ( Stream f) Source #
Instance details

Defined in Streaming.Internal

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> Stream f n a) -> Stream f m b -> Stream f n b Source #

Functor f => MonadTrans ( Stream f) Source #
Instance details

Defined in Streaming.Internal

Methods

lift :: Monad m => m a -> Stream f m a Source #

Functor f => MFunctor ( Stream f :: ( Type -> Type ) -> Type -> Type ) Source #
Instance details

Defined in Streaming.Internal

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Stream f m b -> Stream f n b Source #

( Functor f, Monad m) => Monad ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Functor f, Monad m) => Functor ( Stream f m) Source #

Operates covariantly on the stream result, not on its elements:

Stream (Of a) m r
           ^    ^
           |    `--- This is what Functor and Applicative use
           `--- This is what functions like S.map/S.zipWith use
Instance details

Defined in Streaming.Internal

Methods

fmap :: (a -> b) -> Stream f m a -> Stream f m b Source #

(<$) :: a -> Stream f m b -> Stream f m a Source #

( Functor f, MonadFail m) => MonadFail ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Functor f, Monad m) => Applicative ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Monad m, Functor f, Eq1 m, Eq1 f) => Eq1 ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

Methods

liftEq :: (a -> b -> Bool ) -> Stream f m a -> Stream f m b -> Bool Source #

( Monad m, Functor f, Ord1 m, Ord1 f) => Ord1 ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper)) => Show1 ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( MonadIO m, Functor f) => MonadIO ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Applicative f, Monad m) => Alternative ( Stream f m) Source #

The Alternative instance glues streams together stepwise.

empty = never
(<|>) = zipsWith (liftA2 (,))

See also never , untilJust and delays

Instance details

Defined in Streaming.Internal

( Applicative f, Monad m) => MonadPlus ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

( Monad m, Eq (m ( Either r (f ( Stream f m r))))) => Eq ( Stream f m r) Source #
Instance details

Defined in Streaming.Internal

( Monad m, Ord (m ( Either r (f ( Stream f m r))))) => Ord ( Stream f m r) Source #
Instance details

Defined in Streaming.Internal

( Monad m, Show r, Show (m ShowSWrapper), Show (f ( Stream f m r))) => Show ( Stream f m r) Source #
Instance details

Defined in Streaming.Internal

( Functor f, Monad m, Semigroup w) => Semigroup ( Stream f m w) Source #
Instance details

Defined in Streaming.Internal

( Functor f, Monad m, Monoid w) => Monoid ( Stream f m w) Source #
Instance details

Defined in Streaming.Internal

Constructing a Stream on a given functor

yields :: ( Monad m, Functor f) => f r -> Stream f m r Source #

yields is like lift for items in the streamed functor. It makes a singleton or one-layer succession.

lift :: (Monad m, Functor f)    => m r -> Stream f m r
yields ::  (Monad m, Functor f) => f r -> Stream f m r

Viewed in another light, it is like a functor-general version of yield :

S.yield a = yields (a :> ())

effect :: ( Monad m, Functor f) => m ( Stream f m r) -> Stream f m r Source #

Wrap an effect that returns a stream

effect = join . lift

wrap :: ( Monad m, Functor f) => f ( Stream f m r) -> Stream f m r Source #

Wrap a new layer of a stream. So, e.g.

S.cons :: Monad m => a -> Stream (Of a) m r -> Stream (Of a) m r
S.cons a str = wrap (a :> str)

and, recursively:

S.each :: (Monad m, Foldable t) => t a -> Stream (Of a) m ()
S.each = foldr (\a b -> wrap (a :> b)) (return ())

The two operations

wrap :: (Monad m, Functor f )   => f (Stream f m r) -> Stream f m r
effect :: (Monad m, Functor f ) => m (Stream f m r) -> Stream f m r

are fundamental. We can define the parallel operations yields and lift in terms of them

yields :: (Monad m, Functor f )  => f r -> Stream f m r
yields = wrap . fmap return
lift ::  (Monad m, Functor f )   => m r -> Stream f m r
lift = effect . fmap return

replicates :: ( Monad m, Functor f) => Int -> f () -> Stream f m () Source #

Repeat a functorial layer, command or instruction a fixed number of times.

replicates n = takes n . repeats

repeats :: ( Monad m, Functor f) => f () -> Stream f m r Source #

Repeat a functorial layer (a "command" or "instruction") forever.

repeatsM :: ( Monad m, Functor f) => m (f ()) -> Stream f m r Source #

Repeat an effect containing a functorial layer, command or instruction forever.

unfold :: ( Monad m, Functor f) => (s -> m ( Either r (f s))) -> s -> Stream f m r Source #

Build a Stream by unfolding steps starting from a seed. See also the specialized unfoldr in the prelude.

unfold inspect = id -- modulo the quotient we work with
unfold Pipes.next :: Monad m => Producer a m r -> Stream ((,) a) m r
unfold (curry (:>) . Pipes.next) :: Monad m => Producer a m r -> Stream (Of a) m r

never :: ( Monad m, Applicative f) => Stream f m r Source #

never interleaves the pure applicative action with the return of the monad forever. It is the empty of the Alternative instance, thus

never <|> a = a
a <|> never = a

and so on. If w is a monoid then never :: Stream (Of w) m r is the infinite sequence of mempty , and str1 <|> str2 appends the elements monoidally until one of streams ends. Thus we have, e.g.

>>> S.stdoutLn $ S.take 2 $ S.stdinLn <|> S.repeat " " <|> S.stdinLn  <|> S.repeat " " <|> S.stdinLn
1<Enter>
2<Enter>
3<Enter>
1 2 3
4<Enter>
5<Enter>
6<Enter>
4 5 6

This is equivalent to

>>> S.stdoutLn $ S.take 2 $ foldr (<|>) never [S.stdinLn, S.repeat " ", S.stdinLn, S.repeat " ", S.stdinLn ]

Where f is a monad, (<|>) sequences the conjoined streams stepwise. See the definition of paste here , where the separate steps are bytestreams corresponding to the lines of a file.

Given, say,

data Branch r = Branch r r deriving Functor  -- add obvious applicative instance

then never :: Stream Branch Identity r is the pure infinite binary tree with (inaccessible) r s in its leaves. Given two binary trees, tree1 <|> tree2 intersects them, preserving the leaves that came first, so tree1 <|> never = tree1

Stream Identity m r is an action in m that is indefinitely delayed. Such an action can be constructed with e.g. untilJust .

untilJust :: (Monad m, Applicative f) => m (Maybe r) -> Stream f m r

Given two such items, <|> instance races them. It is thus the iterative monad transformer specially defined in Control.Monad.Trans.Iter

So, for example, we might write

>>> let justFour str = if length str == 4 then Just str else Nothing
>>> let four = untilJust (fmap justFour getLine)
>>> run four
one<Enter>
two<Enter>
three<Enter>
four<Enter>
"four"

The Alternative instance in Control.Monad.Trans.Free is avowedly wrong, though no explanation is given for this.

streamBuild :: ( forall b. (r -> b) -> (m b -> b) -> (f b -> b) -> b) -> Stream f m r Source #

Reflect a church-encoded stream; cp. GHC.Exts.build

streamFold return_ effect_ step_ (streamBuild psi) = psi return_ effect_ step_

Transforming streams

maps :: ( Monad m, Functor f) => ( forall x. f x -> g x) -> Stream f m r -> Stream g m r Source #

Map layers of one functor to another with a transformation. Compare hoist, which has a similar effect on the monadic parameter.

maps id = id
maps f . maps g = maps (f . g)

mapsPost :: forall m f g r. ( Monad m, Functor g) => ( forall x. f x -> g x) -> Stream f m r -> Stream g m r Source #

Map layers of one functor to another with a transformation. Compare hoist, which has a similar effect on the monadic parameter.

mapsPost id = id
mapsPost f . mapsPost g = mapsPost (f . g)
mapsPost f = maps f

mapsPost is essentially the same as maps , but it imposes a Functor constraint on its target functor rather than its source functor. It should be preferred if fmap is cheaper for the target functor than for the source functor.

mapsM :: ( Monad m, Functor f) => ( forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r Source #

Map layers of one functor to another with a transformation involving the base monad. maps is more fundamental than mapsM , which is best understood as a convenience for effecting this frequent composition:

mapsM phi = decompose . maps (Compose . phi)

The streaming prelude exports the same function under the better name mapped , which overlaps with the lens libraries.

mapsMPost :: forall m f g r. ( Monad m, Functor g) => ( forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r Source #

Map layers of one functor to another with a transformation involving the base monad. mapsMPost is essentially the same as mapsM , but it imposes a Functor constraint on its target functor rather than its source functor. It should be preferred if fmap is cheaper for the target functor than for the source functor.

mapsPost is more fundamental than mapsMPost , which is best understood as a convenience for effecting this frequent composition:

mapsMPost phi = decompose . mapsPost (Compose . phi)

The streaming prelude exports the same function under the better name mappedPost , which overlaps with the lens libraries.

mapped :: ( Monad m, Functor f) => ( forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r Source #

Map layers of one functor to another with a transformation involving the base monad.

This function is completely functor-general. It is often useful with the more concrete type

mapped :: (forall x. Stream (Of a) IO x -> IO (Of b x)) -> Stream (Stream (Of a) IO) IO r -> Stream (Of b) IO r

to process groups which have been demarcated in an effectful, IO -based stream by grouping functions like group , split or breaks . Summary functions like fold , foldM , mconcat or toList are often used to define the transformation argument. For example:

>>> S.toList_ $ S.mapped S.toList $ S.split 'c' (S.each "abcde")
["ab","de"]

maps and mapped obey these rules:

maps id              = id
mapped return        = id
maps f . maps g      = maps (f . g)
mapped f . mapped g  = mapped (f <=< g)
maps f . mapped g    = mapped (fmap f . g)
mapped f . maps g    = mapped (f <=< fmap g)

maps is more fundamental than mapped , which is best understood as a convenience for effecting this frequent composition:

mapped phi = decompose . maps (Compose . phi)

mappedPost :: ( Monad m, Functor g) => ( forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r Source #

A version of mapped that imposes a Functor constraint on the target functor rather than the source functor. This version should be preferred if fmap on the target functor is cheaper.

hoistUnexposed :: ( Monad m, Functor f) => ( forall a. m a -> n a) -> Stream f m r -> Stream f n r Source #

A less-efficient version of hoist that works properly even when its argument is not a monad morphism.

hoistUnexposed = hoist . unexposed

distribute :: ( Monad m, Functor f, MonadTrans t, MFunctor t, Monad (t ( Stream f m))) => Stream f (t m) r -> t ( Stream f m) r Source #

Make it possible to 'run' the underlying transformed monad.

groups :: ( Monad m, Functor f, Functor g) => Stream ( Sum f g) m r -> Stream ( Sum ( Stream f m) ( Stream g m)) m r Source #

Group layers in an alternating stream into adjoining sub-streams of one type or another.

Inspecting a stream

inspect :: Monad m => Stream f m r -> m ( Either r (f ( Stream f m r))) Source #

Inspect the first stage of a freely layered sequence. Compare Pipes.next and the replica Streaming.Prelude.next . This is the uncons for the general unfold .

unfold inspect = id
Streaming.Prelude.unfoldr StreamingPrelude.next = id

Splitting and joining Stream s

splitsAt :: ( Monad m, Functor f) => Int -> Stream f m r -> Stream f m ( Stream f m r) Source #

Split a succession of layers after some number, returning a streaming or effectful pair.

>>> rest <- S.print $ S.splitAt 1 $ each [1..3]
1
>>> S.print rest
2
3
splitAt 0 = return
splitAt n >=> splitAt m = splitAt (m+n)

Thus, e.g.

>>> rest <- S.print $ splitsAt 2 >=> splitsAt 2 $ each [1..5]
1
2
3
4
>>> S.print rest
5

chunksOf :: ( Monad m, Functor f) => Int -> Stream f m r -> Stream ( Stream f m) m r Source #

Break a stream into substreams each with n functorial layers.

>>> S.print $ mapped S.sum $ chunksOf 2 $ each [1,1,1,1,1]
2
2
1

concats :: ( Monad m, Functor f) => Stream ( Stream f m) m r -> Stream f m r Source #

Dissolves the segmentation into layers of Stream f m layers.

intercalates :: ( Monad m, Monad (t m), MonadTrans t) => t m x -> Stream (t m) m r -> t m r Source #

Interpolate a layer at each segment. This specializes to e.g.

intercalates :: (Monad m, Functor f) => Stream f m () -> Stream (Stream f m) m r -> Stream f m r

Zipping, unzipping, separating and unseparating streams

zipsWith :: forall f g h m r. ( Monad m, Functor h) => ( forall x y. f x -> g y -> h (x, y)) -> Stream f m r -> Stream g m r -> Stream h m r Source #

Zip two streams together. The zipsWith' function should generally be preferred for efficiency.

zipsWith' :: forall f g h m r. Monad m => ( forall x y p. (x -> y -> p) -> f x -> g y -> h p) -> Stream f m r -> Stream g m r -> Stream h m r Source #

Zip two streams together.

interleaves :: ( Monad m, Applicative h) => Stream h m r -> Stream h m r -> Stream h m r Source #

Interleave functor layers, with the effects of the first preceding the effects of the second. When the first stream runs out, any remaining effects in the second are ignored.

interleaves = zipsWith (liftA2 (,))
>>> let paste = \a b -> interleaves (Q.lines a) (maps (Q.cons' '\t') (Q.lines b))
>>> Q.stdout $ Q.unlines $ paste "hello\nworld\n" "goodbye\nworld\n"
hello	goodbye
world	world

separate :: ( Monad m, Functor f, Functor g) => Stream ( Sum f g) m r -> Stream f ( Stream g m) r Source #

Given a stream on a sum of functors, make it a stream on the left functor, with the streaming on the other functor as the governing monad. This is useful for acting on one or the other functor with a fold, leaving the other material for another treatment. It generalizes partitionEithers , but actually streams properly.

>>> let odd_even = S.maps (S.distinguish even) $ S.each [1..10::Int]
>>> :t separate odd_even
separate odd_even
  :: Monad m => Stream (Of Int) (Stream (Of Int) m) ()

Now, for example, it is convenient to fold on the left and right values separately:

>>> S.toList $ S.toList $ separate odd_even
[2,4,6,8,10] :> ([1,3,5,7,9] :> ())

Or we can write them to separate files or whatever:

>>> S.writeFile "even.txt" . S.show $ S.writeFile "odd.txt" . S.show $ S.separate odd_even
>>> :! cat even.txt
2
4
6
8
10
>>> :! cat odd.txt
1
3
5
7
9

Of course, in the special case of Stream (Of a) m r , we can achieve the above effects more simply by using copy

>>> S.toList . S.filter even $ S.toList . S.filter odd $ S.copy $ each [1..10::Int]
[2,4,6,8,10] :> ([1,3,5,7,9] :> ())

But separate and unseparate are functor-general.

decompose :: ( Monad m, Functor f) => Stream ( Compose m f) m r -> Stream f m r Source #

Rearrange a succession of layers of the form Compose m (f x) .

we could as well define decompose by mapsM :

decompose = mapped getCompose

but mapped is best understood as:

mapped phi = decompose . maps (Compose . phi)

since maps and hoist are the really fundamental operations that preserve the shape of the stream:

maps  :: (Monad m, Functor f) => (forall x. f x -> g x) -> Stream f m r -> Stream g m r
hoist :: (Monad m, Functor f) => (forall a. m a -> n a) -> Stream f m r -> Stream f n r

expand :: ( Monad m, Functor f) => ( forall a b. (g a -> b) -> f a -> h b) -> Stream f m r -> Stream g ( Stream h m) r Source #

If Of had a Comonad instance, then we'd have

copy = expand extend

See expandPost for a version that requires a Functor g instance instead.

expandPost :: ( Monad m, Functor g) => ( forall a b. (g a -> b) -> f a -> h b) -> Stream f m r -> Stream g ( Stream h m) r Source #

If Of had a Comonad instance, then we'd have

copy = expandPost extend

See expand for a version that requires a Functor f instance instead.

Eliminating a Stream

mapsM_ :: ( Functor f, Monad m) => ( forall x. f x -> m x) -> Stream f m r -> m r Source #

Map each layer to an effect, and run them all.

run :: Monad m => Stream m m r -> m r Source #

Run the effects in a stream that merely layers effects.

streamFold :: ( Functor f, Monad m) => (r -> b) -> (m b -> b) -> (f b -> b) -> Stream f m r -> b Source #

streamFold reorders the arguments of destroy to be more akin to foldr It is more convenient to query in ghci to figure out what kind of 'algebra' you need to write.

>>> :t streamFold return join
(Monad m, Functor f) =>
     (f (m a) -> m a) -> Stream f m a -> m a        -- iterT
>>> :t streamFold return (join . lift)
(Monad m, Monad (t m), Functor f, MonadTrans t) =>
     (f (t m a) -> t m a) -> Stream f m a -> t m a  -- iterTM
>>> :t streamFold return effect
(Monad m, Functor f, Functor g) =>
     (f (Stream g m r) -> Stream g m r) -> Stream f m r -> Stream g m r
>>> :t \f -> streamFold return effect (wrap . f)
(Monad m, Functor f, Functor g) =>
     (f (Stream g m a) -> g (Stream g m a))
     -> Stream f m a -> Stream g m a                 -- maps
>>> :t \f -> streamFold return effect (effect . fmap wrap . f)
(Monad m, Functor f, Functor g) =>
     (f (Stream g m a) -> m (g (Stream g m a)))
     -> Stream f m a -> Stream g m a                 -- mapped
    streamFold done eff construct
       = eff . iterT (return . construct . fmap eff) . fmap done

iterTM :: ( Functor f, Monad m, MonadTrans t, Monad (t m)) => (f (t m a) -> t m a) -> Stream f m a -> t m a Source #

Specialized fold following the usage of Control.Monad.Trans.Free

iterTM alg = streamFold return (join . lift)
iterTM alg = iterT alg . hoist lift

iterT :: ( Functor f, Monad m) => (f (m a) -> m a) -> Stream f m a -> m a Source #

Specialized fold following the usage of Control.Monad.Trans.Free

iterT alg = streamFold return join alg
iterT alg = runIdentityT . iterTM (IdentityT . alg . fmap runIdentityT)

destroy :: ( Functor f, Monad m) => Stream f m r -> (f b -> b) -> (m b -> b) -> (r -> b) -> b Source #

Map a stream to its church encoding; compare Data.List.foldr . destroyExposed may be more efficient in some cases when applicable, but it is less safe.

   destroy s construct eff done
     = eff . iterT (return . construct . fmap eff) . fmap done $ s
   

Base functor for streams of individual items

data Of a b Source #

A left-strict pair; the base functor for streams of individual elements.

Constructors

!a :> b infixr 5

Instances

Instances details
Bitraversable Of Source #

Since: 0.2.4.0

Instance details

Defined in Data.Functor.Of

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Of a b -> f ( Of c d) Source #

Bifoldable Of Source #

Since: 0.2.4.0

Instance details

Defined in Data.Functor.Of

Methods

bifold :: Monoid m => Of m m -> m Source #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Of a b -> m Source #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Of a b -> c Source #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Of a b -> c Source #

Bifunctor Of Source #
Instance details

Defined in Data.Functor.Of

Methods

bimap :: (a -> b) -> (c -> d) -> Of a c -> Of b d Source #

first :: (a -> b) -> Of a c -> Of b c Source #

second :: (b -> c) -> Of a b -> Of a c Source #

Eq2 Of Source #
Instance details

Defined in Data.Functor.Of

Methods

liftEq2 :: (a -> b -> Bool ) -> (c -> d -> Bool ) -> Of a c -> Of b d -> Bool Source #

Ord2 Of Source #
Instance details

Defined in Data.Functor.Of

Methods

liftCompare2 :: (a -> b -> Ordering ) -> (c -> d -> Ordering ) -> Of a c -> Of b d -> Ordering Source #

Show2 Of Source #
Instance details

Defined in Data.Functor.Of

Methods

liftShowsPrec2 :: ( Int -> a -> ShowS ) -> ([a] -> ShowS ) -> ( Int -> b -> ShowS ) -> ([b] -> ShowS ) -> Int -> Of a b -> ShowS Source #

liftShowList2 :: ( Int -> a -> ShowS ) -> ([a] -> ShowS ) -> ( Int -> b -> ShowS ) -> ([b] -> ShowS ) -> [ Of a b] -> ShowS Source #

Monoid a => Monad ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

(>>=) :: Of a a0 -> (a0 -> Of a b) -> Of a b Source #

(>>) :: Of a a0 -> Of a b -> Of a b Source #

return :: a0 -> Of a a0 Source #

Functor ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

fmap :: (a0 -> b) -> Of a a0 -> Of a b Source #

(<$) :: a0 -> Of a b -> Of a a0 Source #

Monoid a => Applicative ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

pure :: a0 -> Of a a0 Source #

(<*>) :: Of a (a0 -> b) -> Of a a0 -> Of a b Source #

liftA2 :: (a0 -> b -> c) -> Of a a0 -> Of a b -> Of a c Source #

(*>) :: Of a a0 -> Of a b -> Of a b Source #

(<*) :: Of a a0 -> Of a b -> Of a a0 Source #

Foldable ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

fold :: Monoid m => Of a m -> m Source #

foldMap :: Monoid m => (a0 -> m) -> Of a a0 -> m Source #

foldMap' :: Monoid m => (a0 -> m) -> Of a a0 -> m Source #

foldr :: (a0 -> b -> b) -> b -> Of a a0 -> b Source #

foldr' :: (a0 -> b -> b) -> b -> Of a a0 -> b Source #

foldl :: (b -> a0 -> b) -> b -> Of a a0 -> b Source #

foldl' :: (b -> a0 -> b) -> b -> Of a a0 -> b Source #

foldr1 :: (a0 -> a0 -> a0) -> Of a a0 -> a0 Source #

foldl1 :: (a0 -> a0 -> a0) -> Of a a0 -> a0 Source #

toList :: Of a a0 -> [a0] Source #

null :: Of a a0 -> Bool Source #

length :: Of a a0 -> Int Source #

elem :: Eq a0 => a0 -> Of a a0 -> Bool Source #

maximum :: Ord a0 => Of a a0 -> a0 Source #

minimum :: Ord a0 => Of a a0 -> a0 Source #

sum :: Num a0 => Of a a0 -> a0 Source #

product :: Num a0 => Of a a0 -> a0 Source #

Traversable ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

traverse :: Applicative f => (a0 -> f b) -> Of a a0 -> f ( Of a b) Source #

sequenceA :: Applicative f => Of a (f a0) -> f ( Of a a0) Source #

mapM :: Monad m => (a0 -> m b) -> Of a a0 -> m ( Of a b) Source #

sequence :: Monad m => Of a (m a0) -> m ( Of a a0) Source #

Eq a => Eq1 ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

liftEq :: (a0 -> b -> Bool ) -> Of a a0 -> Of a b -> Bool Source #

Ord a => Ord1 ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

liftCompare :: (a0 -> b -> Ordering ) -> Of a a0 -> Of a b -> Ordering Source #

Show a => Show1 ( Of a) Source #
Instance details

Defined in Data.Functor.Of

Methods

liftShowsPrec :: ( Int -> a0 -> ShowS ) -> ([a0] -> ShowS ) -> Int -> Of a a0 -> ShowS Source #

liftShowList :: ( Int -> a0 -> ShowS ) -> ([a0] -> ShowS ) -> [ Of a a0] -> ShowS Source #

Generic1 ( Of a :: Type -> Type ) Source #
Instance details

Defined in Data.Functor.Of

Associated Types

type Rep1 ( Of a) :: k -> Type Source #

Methods

from1 :: forall (a0 :: k). Of a a0 -> Rep1 ( Of a) a0 Source #

to1 :: forall (a0 :: k). Rep1 ( Of a) a0 -> Of a a0 Source #

( Eq a, Eq b) => Eq ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

( Data a, Data b) => Data ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

Methods

gfoldl :: ( forall d b0. Data d => c (d -> b0) -> d -> c b0) -> ( forall g. g -> c g) -> Of a b -> c ( Of a b) Source #

gunfold :: ( forall b0 r. Data b0 => c (b0 -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Of a b) Source #

toConstr :: Of a b -> Constr Source #

dataTypeOf :: Of a b -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Of a b)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Of a b)) Source #

gmapT :: ( forall b0. Data b0 => b0 -> b0) -> Of a b -> Of a b Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Of a b -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Of a b -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Of a b -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Of a b -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Of a b -> m ( Of a b) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Of a b -> m ( Of a b) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Of a b -> m ( Of a b) Source #

( Ord a, Ord b) => Ord ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

( Read a, Read b) => Read ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

( Show a, Show b) => Show ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

Generic ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

Associated Types

type Rep ( Of a b) :: Type -> Type Source #

( Semigroup a, Semigroup b) => Semigroup ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

( Monoid a, Monoid b) => Monoid ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

type Rep1 ( Of a :: Type -> Type ) Source #
Instance details

Defined in Data.Functor.Of

type Rep ( Of a b) Source #
Instance details

Defined in Data.Functor.Of

lazily :: Of a b -> (a, b) Source #

Note that lazily , strictly , fst' , and mapOf are all so-called natural transformations on the primitive Of a functor. If we write

 type f ~~> g = forall x . f x -> g x

then we can restate some types as follows:

 mapOf            :: (a -> b) -> Of a ~~> Of b   -- Bifunctor first
 lazily           ::             Of a ~~> (,) a
 Identity . fst'  ::             Of a ~~> Identity a

Manipulation of a Stream f m r by mapping often turns on recognizing natural transformations of f . Thus maps is far more general the the map of the Streaming.Prelude , which can be defined thus:

 S.map :: (a -> b) -> Stream (Of a) m r -> Stream (Of b) m r
 S.map f = maps (mapOf f)

i.e.

 S.map f = maps (\(a :> x) -> (f a :> x))

This rests on recognizing that mapOf is a natural transformation; note though that it results in such a transformation as well:

 S.map :: (a -> b) -> Stream (Of a) m ~~> Stream (Of b) m

Thus we can maps it in turn.

strictly :: (a, b) -> Of a b Source #

Convert a standard Haskell pair into a left-strict pair

re-exports

class MFunctor (t :: ( Type -> Type ) -> k -> Type ) where Source #

A functor in the category of monads, using hoist as the analog of fmap :

hoist (f . g) = hoist f . hoist g

hoist id = id

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> t m b -> t n b Source #

Lift a monad morphism from m to n into a monad morphism from (t m) to (t n)

The first argument to hoist must be a monad morphism, even though the type system does not enforce this

Instances

Instances details
MFunctor Lift
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Lift m b -> Lift n b Source #

MFunctor MaybeT
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> MaybeT m b -> MaybeT n b Source #

MFunctor ( IdentityT :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> IdentityT m b -> IdentityT n b Source #

MFunctor ( ExceptT e :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> ExceptT e m b -> ExceptT e n b Source #

MFunctor ( ReaderT r :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> ReaderT r m b -> ReaderT r n b Source #

MFunctor ( StateT s :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> StateT s m b -> StateT s n b Source #

MFunctor ( StateT s :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> StateT s m b -> StateT s n b Source #

MFunctor ( WriterT w :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> WriterT w m b -> WriterT w n b Source #

MFunctor ( WriterT w :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> WriterT w m b -> WriterT w n b Source #

MFunctor ( Backwards :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Backwards m b -> Backwards n b Source #

Functor f => MFunctor ( Stream f :: ( Type -> Type ) -> Type -> Type ) Source #
Instance details

Defined in Streaming.Internal

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Stream f m b -> Stream f n b Source #

MFunctor ( Product f :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Product f m b -> Product f n b Source #

Functor f => MFunctor ( Compose f :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Compose f m b -> Compose f n b Source #

MFunctor ( RWST r w s :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> RWST r w s m b -> RWST r w s n b Source #

MFunctor ( RWST r w s :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> RWST r w s m b -> RWST r w s n b Source #

class ( MFunctor t, MonadTrans t) => MMonad (t :: ( Type -> Type ) -> Type -> Type ) where Source #

A monad in the category of monads, using lift from MonadTrans as the analog of return and embed as the analog of ( =<< ):

embed lift = id

embed f (lift m) = f m

embed g (embed f t) = embed (\m -> embed g (f m)) t

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> t n a) -> t m b -> t n b Source #

Embed a newly created MMonad layer within an existing layer

embed is analogous to ( =<< )

Instances

Instances details
MMonad MaybeT
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> MaybeT n a) -> MaybeT m b -> MaybeT n b Source #

MMonad ( IdentityT :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> IdentityT n a) -> IdentityT m b -> IdentityT n b Source #

MMonad ( ExceptT e)
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> ExceptT e n a) -> ExceptT e m b -> ExceptT e n b Source #

MMonad ( ReaderT r)
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> ReaderT r n a) -> ReaderT r m b -> ReaderT r n b Source #

Monoid w => MMonad ( WriterT w)
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> WriterT w n a) -> WriterT w m b -> WriterT w n b Source #

Monoid w => MMonad ( WriterT w)
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> WriterT w n a) -> WriterT w m b -> WriterT w n b Source #

Functor f => MMonad ( Stream f) Source #
Instance details

Defined in Streaming.Internal

Methods

embed :: forall (n :: Type -> Type ) m b. Monad n => ( forall a. m a -> Stream f n a) -> Stream f m b -> Stream f n b Source #

class MonadTrans (t :: ( Type -> Type ) -> Type -> Type ) where Source #

The class of monad transformers. Instances should satisfy the following laws, which state that lift is a monad transformation:

Methods

lift :: Monad m => m a -> t m a Source #

Lift a computation from the argument monad to the constructed monad.

Instances

Instances details
MonadTrans ListT
Instance details

Defined in Control.Monad.Trans.List

Methods

lift :: Monad m => m a -> ListT m a Source #

MonadTrans MaybeT
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

lift :: Monad m => m a -> MaybeT m a Source #

MonadTrans ( IdentityT :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Trans.Identity

MonadTrans ( ErrorT e)
Instance details

Defined in Control.Monad.Trans.Error

Methods

lift :: Monad m => m a -> ErrorT e m a Source #

MonadTrans ( ExceptT e)
Instance details

Defined in Control.Monad.Trans.Except

Methods

lift :: Monad m => m a -> ExceptT e m a Source #

MonadTrans ( ReaderT r)
Instance details

Defined in Control.Monad.Trans.Reader

Methods

lift :: Monad m => m a -> ReaderT r m a Source #

MonadTrans ( StateT s)
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

lift :: Monad m => m a -> StateT s m a Source #

MonadTrans ( StateT s)
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

lift :: Monad m => m a -> StateT s m a Source #

Monoid w => MonadTrans ( WriterT w)
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

lift :: Monad m => m a -> WriterT w m a Source #

Monoid w => MonadTrans ( WriterT w)
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

lift :: Monad m => m a -> WriterT w m a Source #

Functor f => MonadTrans ( Stream f) Source #
Instance details

Defined in Streaming.Internal

Methods

lift :: Monad m => m a -> Stream f m a Source #

MonadTrans ( ContT r)
Instance details

Defined in Control.Monad.Trans.Cont

Methods

lift :: Monad m => m a -> ContT r m a Source #

Monoid w => MonadTrans ( RWST r w s)
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

lift :: Monad m => m a -> RWST r w s m a Source #

Monoid w => MonadTrans ( RWST r w s)
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

lift :: Monad m => m a -> RWST r w s m a Source #

class Monad m => MonadIO (m :: Type -> Type ) where Source #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

liftIO :: IO a -> m a Source #

Lift a computation from the IO monad.

Instances

Instances details
MonadIO IO

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.IO.Class

MonadIO m => MonadIO ( ListT m)
Instance details

Defined in Control.Monad.Trans.List

MonadIO m => MonadIO ( MaybeT m)
Instance details

Defined in Control.Monad.Trans.Maybe

MonadIO m => MonadIO ( IdentityT m)
Instance details

Defined in Control.Monad.Trans.Identity

( Error e, MonadIO m) => MonadIO ( ErrorT e m)
Instance details

Defined in Control.Monad.Trans.Error

MonadIO m => MonadIO ( ExceptT e m)
Instance details

Defined in Control.Monad.Trans.Except

MonadIO m => MonadIO ( ReaderT r m)
Instance details

Defined in Control.Monad.Trans.Reader

MonadIO m => MonadIO ( StateT s m)
Instance details

Defined in Control.Monad.Trans.State.Lazy

MonadIO m => MonadIO ( StateT s m)
Instance details

Defined in Control.Monad.Trans.State.Strict

( Monoid w, MonadIO m) => MonadIO ( WriterT w m)
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

( Monoid w, MonadIO m) => MonadIO ( WriterT w m)
Instance details

Defined in Control.Monad.Trans.Writer.Strict

( MonadIO m, Functor f) => MonadIO ( Stream f m) Source #
Instance details

Defined in Streaming.Internal

MonadIO m => MonadIO ( ContT r m)
Instance details

Defined in Control.Monad.Trans.Cont

( Monoid w, MonadIO m) => MonadIO ( RWST r w s m)
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

liftIO :: IO a -> RWST r w s m a Source #

( Monoid w, MonadIO m) => MonadIO ( RWST r w s m)
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

liftIO :: IO a -> RWST r w s m a Source #

newtype Compose (f :: k -> Type ) (g :: k1 -> k) (a :: k1) infixr 9 Source #

Right-to-left composition of functors. The composition of applicative functors is always applicative, but the composition of monads is not always a monad.

Constructors

Compose infixr 9

Fields

Instances

Instances details
Functor f => Generic1 ( Compose f g :: k -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Associated Types

type Rep1 ( Compose f g) :: k -> Type Source #

Methods

from1 :: forall (a :: k0). Compose f g a -> Rep1 ( Compose f g) a Source #

to1 :: forall (a :: k0). Rep1 ( Compose f g) a -> Compose f g a Source #

TestEquality f => TestEquality ( Compose f g :: k2 -> Type )

The deduction (via generativity) that if g x :~: g y then x :~: y .

Since: base-4.14.0.0

Instance details

Defined in Data.Functor.Compose

Methods

testEquality :: forall (a :: k) (b :: k). Compose f g a -> Compose f g b -> Maybe (a :~: b) Source #

Functor f => MFunctor ( Compose f :: ( Type -> Type ) -> Type -> Type )
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => ( forall a. m a -> n a) -> Compose f m b -> Compose f n b Source #

( Functor f, Functor g) => Functor ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

fmap :: (a -> b) -> Compose f g a -> Compose f g b Source #

(<$) :: a -> Compose f g b -> Compose f g a Source #

( Applicative f, Applicative g) => Applicative ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Foldable f, Foldable g) => Foldable ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Traversable f, Traversable g) => Traversable ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

traverse :: Applicative f0 => (a -> f0 b) -> Compose f g a -> f0 ( Compose f g b) Source #

sequenceA :: Applicative f0 => Compose f g (f0 a) -> f0 ( Compose f g a) Source #

mapM :: Monad m => (a -> m b) -> Compose f g a -> m ( Compose f g b) Source #

sequence :: Monad m => Compose f g (m a) -> m ( Compose f g a) Source #

( Eq1 f, Eq1 g) => Eq1 ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

liftEq :: (a -> b -> Bool ) -> Compose f g a -> Compose f g b -> Bool Source #

( Ord1 f, Ord1 g) => Ord1 ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Read1 f, Read1 g) => Read1 ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Show1 f, Show1 g) => Show1 ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Alternative f, Applicative g) => Alternative ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Eq1 f, Eq1 g, Eq a) => Eq ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Typeable a, Typeable f, Typeable g, Typeable k1, Typeable k2, Data (f (g a))) => Data ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g0. g0 -> c g0) -> Compose f g a -> c ( Compose f g a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Compose f g a) Source #

toConstr :: Compose f g a -> Constr Source #

dataTypeOf :: Compose f g a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Compose f g a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Compose f g a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Compose f g a -> Compose f g a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Compose f g a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Compose f g a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Compose f g a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Compose f g a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Compose f g a -> m ( Compose f g a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Compose f g a -> m ( Compose f g a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Compose f g a -> m ( Compose f g a) Source #

( Ord1 f, Ord1 g, Ord a) => Ord ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Read1 f, Read1 g, Read a) => Read ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Show1 f, Show1 g, Show a) => Show ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Generic ( Compose f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Associated Types

type Rep ( Compose f g a) :: Type -> Type Source #

type Rep1 ( Compose f g :: k -> Type )
Instance details

Defined in Data.Functor.Compose

type Rep1 ( Compose f g :: k -> Type ) = D1 (' MetaData "Compose" "Data.Functor.Compose" "base" ' True ) ( C1 (' MetaCons "Compose" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getCompose") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) (f :.: Rec1 g)))
type Rep ( Compose f g a)
Instance details

Defined in Data.Functor.Compose

type Rep ( Compose f g a) = D1 (' MetaData "Compose" "Data.Functor.Compose" "base" ' True ) ( C1 (' MetaCons "Compose" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getCompose") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 (f (g a)))))

data Sum (f :: k -> Type ) (g :: k -> Type ) (a :: k) Source #

Lifted sum of functors.

Constructors

InL (f a)
InR (g a)

Instances

Instances details
Generic1 ( Sum f g :: k -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Associated Types

type Rep1 ( Sum f g) :: k -> Type Source #

Methods

from1 :: forall (a :: k0). Sum f g a -> Rep1 ( Sum f g) a Source #

to1 :: forall (a :: k0). Rep1 ( Sum f g) a -> Sum f g a Source #

( Functor f, Functor g) => Functor ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

fmap :: (a -> b) -> Sum f g a -> Sum f g b Source #

(<$) :: a -> Sum f g b -> Sum f g a Source #

( Foldable f, Foldable g) => Foldable ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

fold :: Monoid m => Sum f g m -> m Source #

foldMap :: Monoid m => (a -> m) -> Sum f g a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Sum f g a -> m Source #

foldr :: (a -> b -> b) -> b -> Sum f g a -> b Source #

foldr' :: (a -> b -> b) -> b -> Sum f g a -> b Source #

foldl :: (b -> a -> b) -> b -> Sum f g a -> b Source #

foldl' :: (b -> a -> b) -> b -> Sum f g a -> b Source #

foldr1 :: (a -> a -> a) -> Sum f g a -> a Source #

foldl1 :: (a -> a -> a) -> Sum f g a -> a Source #

toList :: Sum f g a -> [a] Source #

null :: Sum f g a -> Bool Source #

length :: Sum f g a -> Int Source #

elem :: Eq a => a -> Sum f g a -> Bool Source #

maximum :: Ord a => Sum f g a -> a Source #

minimum :: Ord a => Sum f g a -> a Source #

sum :: Num a => Sum f g a -> a Source #

product :: Num a => Sum f g a -> a Source #

( Traversable f, Traversable g) => Traversable ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

traverse :: Applicative f0 => (a -> f0 b) -> Sum f g a -> f0 ( Sum f g b) Source #

sequenceA :: Applicative f0 => Sum f g (f0 a) -> f0 ( Sum f g a) Source #

mapM :: Monad m => (a -> m b) -> Sum f g a -> m ( Sum f g b) Source #

sequence :: Monad m => Sum f g (m a) -> m ( Sum f g a) Source #

( Eq1 f, Eq1 g) => Eq1 ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

liftEq :: (a -> b -> Bool ) -> Sum f g a -> Sum f g b -> Bool Source #

( Ord1 f, Ord1 g) => Ord1 ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

liftCompare :: (a -> b -> Ordering ) -> Sum f g a -> Sum f g b -> Ordering Source #

( Read1 f, Read1 g) => Read1 ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

( Show1 f, Show1 g) => Show1 ( Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

( Eq1 f, Eq1 g, Eq a) => Eq ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

( Typeable a, Typeable f, Typeable g, Typeable k, Data (f a), Data (g a)) => Data ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g0. g0 -> c g0) -> Sum f g a -> c ( Sum f g a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Sum f g a) Source #

toConstr :: Sum f g a -> Constr Source #

dataTypeOf :: Sum f g a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Sum f g a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Sum f g a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Sum f g a -> Sum f g a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Sum f g a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Sum f g a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Sum f g a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Sum f g a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Sum f g a -> m ( Sum f g a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Sum f g a -> m ( Sum f g a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Sum f g a -> m ( Sum f g a) Source #

( Ord1 f, Ord1 g, Ord a) => Ord ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

( Read1 f, Read1 g, Read a) => Read ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

( Show1 f, Show1 g, Show a) => Show ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Generic ( Sum f g a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Associated Types

type Rep ( Sum f g a) :: Type -> Type Source #

Methods

from :: Sum f g a -> Rep ( Sum f g a) x Source #

to :: Rep ( Sum f g a) x -> Sum f g a Source #

type Rep1 ( Sum f g :: k -> Type )
Instance details

Defined in Data.Functor.Sum

type Rep ( Sum f g a)
Instance details

Defined in Data.Functor.Sum

newtype Identity a Source #

Identity functor and monad. (a non-strict monad)

Since: base-4.8.0.0

Constructors

Identity

Fields

Instances

Instances details
Monad Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Functor Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

MonadFix Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Applicative Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Foldable Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Traversable Identity

Since: base-4.9.0.0

Instance details

Defined in Data.Traversable

Eq1 Identity

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Ord1 Identity

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Read1 Identity

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Show1 Identity

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Classes

Bounded a => Bounded ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Enum a => Enum ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Eq a => Eq ( Identity a)

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Floating a => Floating ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Fractional a => Fractional ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Integral a => Integral ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Data a => Data ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Data

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Identity a -> c ( Identity a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Identity a) Source #

toConstr :: Identity a -> Constr Source #

dataTypeOf :: Identity a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Identity a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Identity a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Identity a -> Identity a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Identity a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Identity a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Identity a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Identity a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Identity a -> m ( Identity a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Identity a -> m ( Identity a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Identity a -> m ( Identity a) Source #

Num a => Num ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Ord a => Ord ( Identity a)

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Read a => Read ( Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Real a => Real ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

RealFloat a => RealFloat ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

RealFrac a => RealFrac ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Show a => Show ( Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Ix a => Ix ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Generic ( Identity a)

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Associated Types

type Rep ( Identity a) :: Type -> Type Source #

Semigroup a => Semigroup ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Monoid a => Monoid ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Storable a => Storable ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Bits a => Bits ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

FiniteBits a => FiniteBits ( Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Identity

Generic1 Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Associated Types

type Rep1 Identity :: k -> Type Source #

type Rep ( Identity a)
Instance details

Defined in Data.Functor.Identity

type Rep ( Identity a) = D1 (' MetaData "Identity" "Data.Functor.Identity" "base" ' True ) ( C1 (' MetaCons "Identity" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "runIdentity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 a)))
type Rep1 Identity
Instance details

Defined in Data.Functor.Identity

type Rep1 Identity = D1 (' MetaData "Identity" "Data.Functor.Identity" "base" ' True ) ( C1 (' MetaCons "Identity" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "runIdentity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) Par1 ))

class Applicative f => Alternative (f :: Type -> Type ) where Source #

A monoid on applicative functors.

If defined, some and many should be the least solutions of the equations:

Minimal complete definition

empty , (<|>)

Methods

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

An associative binary operation

Instances

Instances details
Alternative []

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

empty :: [a] Source #

(<|>) :: [a] -> [a] -> [a] Source #

some :: [a] -> [[a]] Source #

many :: [a] -> [[a]] Source #

Alternative Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Alternative IO

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Alternative Option

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Alternative ZipList

Since: base-4.11.0.0

Instance details

Defined in Control.Applicative

Alternative ReadPrec

Since: base-4.6.0.0

Instance details

Defined in Text.ParserCombinators.ReadPrec

Alternative ReadP

Since: base-4.6.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Alternative Seq

Since: containers-0.5.4

Instance details

Defined in Data.Sequence.Internal

Alternative P

Since: base-4.5.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

empty :: P a Source #

(<|>) :: P a -> P a -> P a Source #

some :: P a -> P [a] Source #

many :: P a -> P [a] Source #

Alternative ( U1 :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

MonadPlus m => Alternative ( WrappedMonad m)

Since: base-2.1

Instance details

Defined in Control.Applicative

ArrowPlus a => Alternative ( ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Alternative ( Proxy :: Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Applicative m => Alternative ( ListT m)
Instance details

Defined in Control.Monad.Trans.List

Alternative f => Alternative ( Lift f)

A combination is Pure only either part is.

Instance details

Defined in Control.Applicative.Lift

( Functor m, Monad m) => Alternative ( MaybeT m)
Instance details

Defined in Control.Monad.Trans.Maybe

Alternative f => Alternative ( Rec1 f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

( ArrowZero a, ArrowPlus a) => Alternative ( WrappedArrow a b)

Since: base-2.1

Instance details

Defined in Control.Applicative

Alternative m => Alternative ( Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Alternative f => Alternative ( Ap f)

Since: base-4.12.0.0

Instance details

Defined in Data.Monoid

Alternative f => Alternative ( Alt f)

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Alternative m => Alternative ( IdentityT m)
Instance details

Defined in Control.Monad.Trans.Identity

( Functor m, Monad m, Error e) => Alternative ( ErrorT e m)
Instance details

Defined in Control.Monad.Trans.Error

( Functor m, Monad m, Monoid e) => Alternative ( ExceptT e m)
Instance details

Defined in Control.Monad.Trans.Except

Alternative m => Alternative ( ReaderT r m)
Instance details

Defined in Control.Monad.Trans.Reader

( Functor m, MonadPlus m) => Alternative ( StateT s m)
Instance details

Defined in Control.Monad.Trans.State.Lazy

( Functor m, MonadPlus m) => Alternative ( StateT s m)
Instance details

Defined in Control.Monad.Trans.State.Strict

( Monoid w, Alternative m) => Alternative ( WriterT w m)
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

( Monoid w, Alternative m) => Alternative ( WriterT w m)
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Alternative f => Alternative ( Backwards f)

Try alternatives in the same order as f .

Instance details

Defined in Control.Applicative.Backwards

( Applicative f, Monad m) => Alternative ( Stream f m) Source #

The Alternative instance glues streams together stepwise.

empty = never
(<|>) = zipsWith (liftA2 (,))

See also never , untilJust and delays

Instance details

Defined in Streaming.Internal

( Alternative f, Alternative g) => Alternative (f :*: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: (f :*: g) a Source #

(<|>) :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a Source #

some :: (f :*: g) a -> (f :*: g) [a] Source #

many :: (f :*: g) a -> (f :*: g) [a] Source #

( Alternative f, Alternative g) => Alternative ( Product f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Alternative f => Alternative ( M1 i c f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: M1 i c f a Source #

(<|>) :: M1 i c f a -> M1 i c f a -> M1 i c f a Source #

some :: M1 i c f a -> M1 i c f [a] Source #

many :: M1 i c f a -> M1 i c f [a] Source #

( Alternative f, Applicative g) => Alternative (f :.: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: (f :.: g) a Source #

(<|>) :: (f :.: g) a -> (f :.: g) a -> (f :.: g) a Source #

some :: (f :.: g) a -> (f :.: g) [a] Source #

many :: (f :.: g) a -> (f :.: g) [a] Source #

( Alternative f, Applicative g) => Alternative ( Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

( Monoid w, Functor m, MonadPlus m) => Alternative ( RWST r w s m)
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

empty :: RWST r w s m a Source #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

some :: RWST r w s m a -> RWST r w s m [a] Source #

many :: RWST r w s m a -> RWST r w s m [a] Source #

( Monoid w, Functor m, MonadPlus m) => Alternative ( RWST r w s m)
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

empty :: RWST r w s m a Source #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

some :: RWST r w s m a -> RWST r w s m [a] Source #

many :: RWST r w s m a -> RWST r w s m [a] Source #

class Bifunctor (p :: Type -> Type -> Type ) where Source #

A bifunctor is a type constructor that takes two type arguments and is a functor in both arguments. That is, unlike with Functor , a type constructor such as Either does not need to be partially applied for a Bifunctor instance, and the methods in this class permit mapping functions over the Left value or the Right value, or both at the same time.

Formally, the class Bifunctor represents a bifunctor from Hask -> Hask .

Intuitively it is a bifunctor where both the first and second arguments are covariant.

You can define a Bifunctor by either defining bimap or by defining both first and second .

If you supply bimap , you should ensure that:

bimap id idid

If you supply first and second , ensure:

first idid
second idid

If you supply both, you should also ensure:

bimap f g ≡ first f . second g

These ensure by parametricity:

bimap  (f . g) (h . i) ≡ bimap f h . bimap g i
first  (f . g) ≡ first  f . first  g
second (f . g) ≡ second f . second g

Since: base-4.8.0.0

Minimal complete definition

bimap | first , second

Methods

bimap :: (a -> b) -> (c -> d) -> p a c -> p b d Source #

Map over both arguments at the same time.

bimap f g ≡ first f . second g

Examples

Expand
>>> bimap toUpper (+1) ('j', 3)
('J',4)
>>> bimap toUpper (+1) (Left 'j')
Left 'J'
>>> bimap toUpper (+1) (Right 3)
Right 4

first :: (a -> b) -> p a c -> p b c Source #

Map covariantly over the first argument.

first f ≡ bimap f id

Examples

Expand
>>> first toUpper ('j', 3)
('J',3)
>>> first toUpper (Left 'j')
Left 'J'

second :: (b -> c) -> p a b -> p a c Source #

Map covariantly over the second argument.

secondbimap id

Examples

Expand
>>> second (+1) ('j', 3)
('j',4)
>>> second (+1) (Right 3)
Right 4

Instances

Instances details
Bifunctor Either

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> Either a c -> Either b d Source #

first :: (a -> b) -> Either a c -> Either b c Source #

second :: (b -> c) -> Either a b -> Either a c Source #

Bifunctor (,)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) Source #

first :: (a -> b) -> (a, c) -> (b, c) Source #

second :: (b -> c) -> (a, b) -> (a, c) Source #

Bifunctor Arg

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

bimap :: (a -> b) -> (c -> d) -> Arg a c -> Arg b d Source #

first :: (a -> b) -> Arg a c -> Arg b c Source #

second :: (b -> c) -> Arg a b -> Arg a c Source #

Bifunctor Of Source #
Instance details

Defined in Data.Functor.Of

Methods

bimap :: (a -> b) -> (c -> d) -> Of a c -> Of b d Source #

first :: (a -> b) -> Of a c -> Of b c Source #

second :: (b -> c) -> Of a b -> Of a c Source #

Bifunctor ( (,,) x1)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, a, c) -> (x1, b, d) Source #

first :: (a -> b) -> (x1, a, c) -> (x1, b, c) Source #

second :: (b -> c) -> (x1, a, b) -> (x1, a, c) Source #

Bifunctor ( Const :: Type -> Type -> Type )

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> Const a c -> Const b d Source #

first :: (a -> b) -> Const a c -> Const b c Source #

second :: (b -> c) -> Const a b -> Const a c Source #

Bifunctor ( K1 i :: Type -> Type -> Type )

Since: base-4.9.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> K1 i a c -> K1 i b d Source #

first :: (a -> b) -> K1 i a c -> K1 i b c Source #

second :: (b -> c) -> K1 i a b -> K1 i a c Source #

Bifunctor ( (,,,) x1 x2)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, a, c) -> (x1, x2, b, d) Source #

first :: (a -> b) -> (x1, x2, a, c) -> (x1, x2, b, c) Source #

second :: (b -> c) -> (x1, x2, a, b) -> (x1, x2, a, c) Source #

Bifunctor ( (,,,,) x1 x2 x3)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, a, c) -> (x1, x2, x3, b, d) Source #

first :: (a -> b) -> (x1, x2, x3, a, c) -> (x1, x2, x3, b, c) Source #

second :: (b -> c) -> (x1, x2, x3, a, b) -> (x1, x2, x3, a, c) Source #

Bifunctor ( (,,,,,) x1 x2 x3 x4)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, x4, a, c) -> (x1, x2, x3, x4, b, d) Source #

first :: (a -> b) -> (x1, x2, x3, x4, a, c) -> (x1, x2, x3, x4, b, c) Source #

second :: (b -> c) -> (x1, x2, x3, x4, a, b) -> (x1, x2, x3, x4, a, c) Source #

Bifunctor ( (,,,,,,) x1 x2 x3 x4 x5)

Since: base-4.8.0.0

Instance details

Defined in Data.Bifunctor

Methods

bimap :: (a -> b) -> (c -> d) -> (x1, x2, x3, x4, x5, a, c) -> (x1, x2, x3, x4, x5, b, d) Source #

first :: (a -> b) -> (x1, x2, x3, x4, x5, a, c) -> (x1, x2, x3, x4, x5, b, c) Source #

second :: (b -> c) -> (x1, x2, x3, x4, x5, a, b) -> (x1, x2, x3, x4, x5, a, c) Source #

join :: Monad m => m (m a) -> m a Source #

The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level.

' join bss ' can be understood as the do expression

do bs <- bss
   bs

Examples

Expand

A common use of join is to run an IO computation returned from an STM transaction, since STM transactions can't perform IO directly. Recall that

atomically :: STM a -> IO a

is used to run STM transactions atomically. So, by specializing the types of atomically and join to

atomically :: STM (IO b) -> IO (IO b)
join       :: IO (IO b)  -> IO b

we can compose them as

join . atomically :: STM (IO b) -> IO b

to run an STM transaction and the IO action it returns.

liftM :: Monad m => (a1 -> r) -> m a1 -> m r Source #

Promote a function to a monad.

liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r Source #

Promote a function to a monad, scanning the monadic arguments from left to right. For example,

liftM2 (+) [0,1] [0,2] = [0,2,1,3]
liftM2 (+) (Just 1) Nothing = Nothing

liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c Source #

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 : ' liftA2 f as bs ' can be understood as the do expression

do a <- as
   b <- bs
   pure (f a b)

liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d Source #

Lift a ternary function to actions.

Using ApplicativeDo : ' liftA3 f as bs cs ' can be understood as the do expression

do a <- as
   b <- bs
   c <- cs
   pure (f a b c)

void :: Functor f => f a -> f () Source #

void value discards or ignores the result of evaluation, such as the return value of an IO action.

Using ApplicativeDo : ' void as ' can be understood as the do expression

do as
   pure ()

with an inferred Functor constraint.

Examples

Expand

Replace the contents of a Maybe Int with unit:

>>> void Nothing
Nothing
>>> void (Just 3)
Just ()

Replace the contents of an Either Int Int with unit, resulting in an Either Int () :

>>> void (Left 8675309)
Left 8675309
>>> void (Right 8675309)
Right ()

Replace every element of a list with unit:

>>> void [1,2,3]
[(),(),()]

Replace the second element of a pair with unit:

>>> void (1,2)
(1,())

Discard the result of an IO action:

>>> mapM print [1,2]
1
2
[(),()]
>>> void $ mapM print [1,2]
1
2

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

An associative operation.

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