streaming-0.1.4.5: an elementary streaming prelude and general stream type.

Safe HaskellTrustworthy
LanguageHaskell2010

Streaming

Contents

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

(MonadBase b m, Functor f) => MonadBase b (Stream f m) Source # 

Methods

liftBase :: b α -> Stream f m α #

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

Methods

throwError :: e -> Stream f m a #

catchError :: Stream f m a -> (e -> Stream f m a) -> Stream f m a #

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

Methods

ask :: Stream f m r #

local :: (r -> r) -> Stream f m a -> Stream f m a #

reader :: (r -> a) -> Stream f m a #

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

Methods

get :: Stream f m s #

put :: s -> Stream f m () #

state :: (s -> (a, s)) -> Stream f m a #

Functor f => MFunctor (Stream f) Source # 

Methods

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

Functor f => MMonad (Stream f) Source # 

Methods

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

Functor f => MonadTrans (Stream f) Source # 

Methods

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

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

Methods

(>>=) :: Stream f m a -> (a -> Stream f m b) -> Stream f m b #

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

return :: a -> Stream f m a #

fail :: String -> Stream f m a #

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

Methods

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

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

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

Methods

pure :: a -> Stream f m a #

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

(*>) :: Stream f m a -> Stream f m b -> Stream f m b #

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

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

Methods

liftIO :: IO a -> Stream f m a #

(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

Methods

empty :: Stream f m a #

(<|>) :: Stream f m a -> Stream f m a -> Stream f m a #

some :: Stream f m a -> Stream f m [a] #

many :: Stream f m a -> Stream f m [a] #

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

Methods

mzero :: Stream f m a #

mplus :: Stream f m a -> Stream f m a -> Stream f m a #

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

Methods

throwM :: Exception e => e -> Stream f m a #

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

Methods

catch :: Exception e => Stream f m a -> (e -> Stream f m a) -> Stream f m a #

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

Methods

liftResourceT :: ResourceT IO a -> Stream f m a #

(Eq r, Eq (m (Stream f m r)), Eq (f (Stream f m r))) => Eq (Stream f m r) Source # 

Methods

(==) :: Stream f m r -> Stream f m r -> Bool #

(/=) :: Stream f m r -> Stream f m r -> Bool #

(Typeable (* -> *) f, Typeable (* -> *) m, Data r, Data (m (Stream f m r)), Data (f (Stream f m r))) => Data (Stream f m r) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Stream f m r -> c (Stream f m r) #

gunfold :: (forall b a. Data b => c (b -> a) -> c a) -> (forall a. a -> c a) -> Constr -> c (Stream f m r) #

toConstr :: Stream f m r -> Constr #

dataTypeOf :: Stream f m r -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Stream f m r)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Stream f m r)) #

gmapT :: (forall b. Data b => b -> b) -> Stream f m r -> Stream f m r #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stream f m r -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stream f m r -> r #

gmapQ :: (forall d. Data d => d -> u) -> Stream f m r -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Stream f m r -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Stream f m r -> m (Stream f m r) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Stream f m r -> m (Stream f m r) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Stream f m r -> m (Stream f m r) #

(Show r, Show (m (Stream f m r)), Show (f (Stream f m r))) => Show (Stream f m r) Source # 

Methods

showsPrec :: Int -> Stream f m r -> ShowS #

show :: Stream f m r -> String #

showList :: [Stream f m r] -> ShowS #

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

Methods

mempty :: Stream f m w #

mappend :: Stream f m w -> Stream f m w -> Stream f m w #

mconcat :: [Stream f m w] -> Stream f m w #

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) rs 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 (liftM 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.

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

Repeat a

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)

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.

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 could be trivial, e.g.

let noteBeginning text x = putStrLn text >> return text

this puts the is completely functor-general

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 (liftM f . g)
mapped f . maps g    = mapped (f <=< liftM 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)

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 :: (Functor f, 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 Streams

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

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

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

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

Zipping, unzipping, separating and unseparating streams

zipsWith :: (Monad m, Functor f, Functor g, 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 #

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

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

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.

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:

>>> runResourceT $ 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.

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

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

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 . liftM 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

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)

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

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

Map a stream directly to its church encoding; compare Data.List.foldr

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

Bifunctor Of Source # 

Methods

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

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

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

Monoid a => Monad (Of a) Source # 

Methods

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

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

return :: a -> Of a a #

fail :: String -> Of a a #

Functor (Of a) Source # 

Methods

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

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

Monoid a => Applicative (Of a) Source # 

Methods

pure :: a -> Of a a #

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

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

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

Foldable (Of a) Source # 

Methods

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

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

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

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

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

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

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

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

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

null :: Of a a -> Bool #

length :: Of a a -> Int #

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

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

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

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

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

Traversable (Of a) Source # 

Methods

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

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

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

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

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

Methods

(==) :: Of a b -> Of a b -> Bool #

(/=) :: Of a b -> Of a b -> Bool #

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

Methods

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

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

toConstr :: Of a b -> Constr #

dataTypeOf :: Of a b -> DataType #

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

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

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

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

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

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

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

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

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

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

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

Methods

compare :: Of a b -> Of a b -> Ordering #

(<) :: Of a b -> Of a b -> Bool #

(<=) :: Of a b -> Of a b -> Bool #

(>) :: Of a b -> Of a b -> Bool #

(>=) :: Of a b -> Of a b -> Bool #

max :: Of a b -> Of a b -> Of a b #

min :: Of a b -> Of a b -> Of a b #

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

Methods

readsPrec :: Int -> ReadS (Of a b) #

readList :: ReadS [Of a b] #

readPrec :: ReadPrec (Of a b) #

readListPrec :: ReadPrec [Of a b] #

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

Methods

showsPrec :: Int -> Of a b -> ShowS #

show :: Of a b -> String #

showList :: [Of a b] -> ShowS #

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

Methods

mempty :: Of a b #

mappend :: Of a b -> Of a b -> Of a b #

mconcat :: [Of a b] -> Of a b #

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

ResourceT help

bracketStream :: (Functor f, MonadResource m) => IO a -> (a -> IO ()) -> (a -> Stream f m b) -> Stream f m b Source #

re-exports

class MFunctor t where #

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

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

hoist id = id

Instances

MFunctor ListT 

Methods

hoist :: Monad m => (forall a. m a -> n a) -> ListT m b -> ListT n b #

MFunctor ResourceT

Since 0.4.7

Methods

hoist :: Monad m => (forall a. m a -> n a) -> ResourceT m b -> ResourceT n b #

MFunctor Lift 

Methods

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

MFunctor MaybeT 

Methods

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

MFunctor (ExceptT e) 

Methods

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

MFunctor (ErrorT e) 

Methods

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

MFunctor (StateT s) 

Methods

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

MFunctor (StateT s) 

Methods

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

MFunctor (WriterT w) 

Methods

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

MFunctor (WriterT w) 

Methods

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

MFunctor (Backwards *) 

Methods

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

MFunctor (IdentityT *) 

Methods

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

Functor f => MFunctor (Stream f) # 

Methods

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

MFunctor (Product * f) 

Methods

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

MFunctor (ReaderT * r) 

Methods

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

Functor f => MFunctor (Compose * * f) 

Methods

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

MFunctor (RWST r w s) 

Methods

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

MFunctor (RWST r w s) 

Methods

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

class (MFunctor t, MonadTrans t) => MMonad t where #

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

Instances

MMonad ListT 

Methods

embed :: Monad n => (forall a. m a -> ListT n a) -> ListT m b -> ListT n b #

MMonad ResourceT

Since 0.4.7

Methods

embed :: Monad n => (forall a. m a -> ResourceT n a) -> ResourceT m b -> ResourceT n b #

MMonad MaybeT 

Methods

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

MMonad (ExceptT e) 

Methods

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

Error e => MMonad (ErrorT e) 

Methods

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

Monoid w => MMonad (WriterT w) 

Methods

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

Monoid w => MMonad (WriterT w) 

Methods

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

MMonad (IdentityT *) 

Methods

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

Functor f => MMonad (Stream f) # 

Methods

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

MMonad (ReaderT * r) 

Methods

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

class MonadTrans t where #

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

Instances

MonadTrans ListT 

Methods

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

MonadTrans ResourceT 

Methods

lift :: Monad m => m a -> ResourceT m a #

MonadTrans MaybeT 

Methods

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

MonadTrans (ExceptT e) 

Methods

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

MonadTrans (ErrorT e) 

Methods

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

MonadTrans (StateT s) 

Methods

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

MonadTrans (StateT s) 

Methods

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

Monoid w => MonadTrans (WriterT w) 

Methods

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

Monoid w => MonadTrans (WriterT w) 

Methods

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

MonadTrans (IdentityT *) 

Methods

lift :: Monad m => m a -> IdentityT * m a #

Functor f => MonadTrans (Stream f) # 

Methods

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

MonadTrans (ContT * r) 

Methods

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

MonadTrans (ReaderT * r) 

Methods

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

Monoid w => MonadTrans (RWST r w s) 

Methods

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

Monoid w => MonadTrans (RWST r w s) 

Methods

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

class Monad m => MonadIO m where #

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:

Instances

MonadIO IO 

Methods

liftIO :: IO a -> IO a #

MonadIO m => MonadIO (ListT m) 

Methods

liftIO :: IO a -> ListT m a #

MonadIO m => MonadIO (ResourceT m) 

Methods

liftIO :: IO a -> ResourceT m a #

MonadIO m => MonadIO (MaybeT m) 

Methods

liftIO :: IO a -> MaybeT m a #

MonadIO m => MonadIO (ExceptT e m) 

Methods

liftIO :: IO a -> ExceptT e m a #

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

Methods

liftIO :: IO a -> ErrorT e m a #

MonadIO m => MonadIO (StateT s m) 

Methods

liftIO :: IO a -> StateT s m a #

MonadIO m => MonadIO (StateT s m) 

Methods

liftIO :: IO a -> StateT s m a #

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

Methods

liftIO :: IO a -> WriterT w m a #

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

Methods

liftIO :: IO a -> WriterT w m a #

MonadIO m => MonadIO (IdentityT * m) 

Methods

liftIO :: IO a -> IdentityT * m a #

(MonadIO m, Functor f) => MonadIO (Stream f m) # 

Methods

liftIO :: IO a -> Stream f m a #

MonadIO m => MonadIO (ContT * r m) 

Methods

liftIO :: IO a -> ContT * r m a #

MonadIO m => MonadIO (ReaderT * r m) 

Methods

liftIO :: IO a -> ReaderT * r m a #

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

Methods

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

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

Methods

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

newtype Compose k k1 f g a :: forall k k1. (k -> *) -> (k1 -> k) -> k1 -> * infixr 9 #

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

Functor f => MFunctor (Compose * * f) 

Methods

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

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

Methods

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

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

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

Methods

pure :: a -> Compose * * f g a #

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

(*>) :: Compose * * f g a -> Compose * * f g b -> Compose * * f g b #

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

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

Methods

fold :: Monoid m => Compose * * f g m -> m #

foldMap :: Monoid m => (a -> m) -> Compose * * f g a -> m #

foldr :: (a -> b -> b) -> b -> Compose * * f g a -> b #

foldr' :: (a -> b -> b) -> b -> Compose * * f g a -> b #

foldl :: (b -> a -> b) -> b -> Compose * * f g a -> b #

foldl' :: (b -> a -> b) -> b -> Compose * * f g a -> b #

foldr1 :: (a -> a -> a) -> Compose * * f g a -> a #

foldl1 :: (a -> a -> a) -> Compose * * f g a -> a #

toList :: Compose * * f g a -> [a] #

null :: Compose * * f g a -> Bool #

length :: Compose * * f g a -> Int #

elem :: Eq a => a -> Compose * * f g a -> Bool #

maximum :: Ord a => Compose * * f g a -> a #

minimum :: Ord a => Compose * * f g a -> a #

sum :: Num a => Compose * * f g a -> a #

product :: Num a => Compose * * f g a -> a #

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

Methods

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

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

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

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

Functor f => Generic1 (Compose * * f g) 

Associated Types

type Rep1 (Compose * * f g :: * -> *) :: * -> * #

Methods

from1 :: Compose * * f g a -> Rep1 (Compose * * f g) a #

to1 :: Rep1 (Compose * * f g) a -> Compose * * f g a #

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

Methods

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

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

Methods

liftCompare :: (a -> b -> Ordering) -> Compose * * f g a -> Compose * * f g b -> Ordering #

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

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Compose * * f g a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Compose * * f g a] #

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

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Compose * * f g a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Compose * * f g a] -> ShowS #

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

Methods

empty :: Compose * * f g a #

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

some :: Compose * * f g a -> Compose * * f g [a] #

many :: Compose * * f g a -> Compose * * f g [a] #

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

Methods

(==) :: Compose * * f g a -> Compose * * f g a -> Bool #

(/=) :: Compose * * f g a -> Compose * * f g a -> Bool #

(Data (f (g a)), Typeable k1 a, Typeable * k, Typeable * k1, Typeable (k -> *) f, Typeable (k1 -> k) g) => Data (Compose k k1 f g a) 

Methods

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

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

toConstr :: Compose k k1 f g a -> Constr #

dataTypeOf :: Compose k k1 f g a -> DataType #

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

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

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

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

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

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

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

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

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

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

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

Methods

compare :: Compose * * f g a -> Compose * * f g a -> Ordering #

(<) :: Compose * * f g a -> Compose * * f g a -> Bool #

(<=) :: Compose * * f g a -> Compose * * f g a -> Bool #

(>) :: Compose * * f g a -> Compose * * f g a -> Bool #

(>=) :: Compose * * f g a -> Compose * * f g a -> Bool #

max :: Compose * * f g a -> Compose * * f g a -> Compose * * f g a #

min :: Compose * * f g a -> Compose * * f g a -> Compose * * f g a #

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

Methods

readsPrec :: Int -> ReadS (Compose * * f g a) #

readList :: ReadS [Compose * * f g a] #

readPrec :: ReadPrec (Compose * * f g a) #

readListPrec :: ReadPrec [Compose * * f g a] #

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

Methods

showsPrec :: Int -> Compose * * f g a -> ShowS #

show :: Compose * * f g a -> String #

showList :: [Compose * * f g a] -> ShowS #

Generic (Compose k k1 f g a) 

Associated Types

type Rep (Compose k k1 f g a) :: * -> * #

Methods

from :: Compose k k1 f g a -> Rep (Compose k k1 f g a) x #

to :: Rep (Compose k k1 f g a) x -> Compose k k1 f g a #

type Rep1 (Compose * * f g) 
type Rep1 (Compose * * f g) = D1 (MetaData "Compose" "Data.Functor.Compose" "base" True) (C1 (MetaCons "Compose" PrefixI True) (S1 (MetaSel (Just Symbol "getCompose") NoSourceUnpackedness NoSourceStrictness DecidedLazy) ((:.:) f (Rec1 g))))
type Rep (Compose k k1 f g a) 
type Rep (Compose k k1 f g a) = D1 (MetaData "Compose" "Data.Functor.Compose" "base" True) (C1 (MetaCons "Compose" PrefixI True) (S1 (MetaSel (Just Symbol "getCompose") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f (g a)))))

data Sum k f g a :: forall k. (k -> *) -> (k -> *) -> k -> * #

Lifted sum of functors.

Constructors

InL (f a) 
InR (g a) 

Instances

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

Methods

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

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

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

Methods

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Methods

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

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

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

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

Generic1 (Sum * f g) 

Associated Types

type Rep1 (Sum * f g :: * -> *) :: * -> * #

Methods

from1 :: Sum * f g a -> Rep1 (Sum * f g) a #

to1 :: Rep1 (Sum * f g) a -> Sum * f g a #

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

Methods

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

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

Methods

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

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

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Sum * f g a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Sum * f g a] #

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

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Sum * f g a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Sum * f g a] -> ShowS #

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

Methods

(==) :: Sum * f g a -> Sum * f g a -> Bool #

(/=) :: Sum * f g a -> Sum * f g a -> Bool #

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

Methods

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Methods

compare :: Sum * f g a -> Sum * f g a -> Ordering #

(<) :: Sum * f g a -> Sum * f g a -> Bool #

(<=) :: Sum * f g a -> Sum * f g a -> Bool #

(>) :: Sum * f g a -> Sum * f g a -> Bool #

(>=) :: Sum * f g a -> Sum * f g a -> Bool #

max :: Sum * f g a -> Sum * f g a -> Sum * f g a #

min :: Sum * f g a -> Sum * f g a -> Sum * f g a #

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

Methods

readsPrec :: Int -> ReadS (Sum * f g a) #

readList :: ReadS [Sum * f g a] #

readPrec :: ReadPrec (Sum * f g a) #

readListPrec :: ReadPrec [Sum * f g a] #

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

Methods

showsPrec :: Int -> Sum * f g a -> ShowS #

show :: Sum * f g a -> String #

showList :: [Sum * f g a] -> ShowS #

Generic (Sum k f g a) 

Associated Types

type Rep (Sum k f g a) :: * -> * #

Methods

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

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

type Rep1 (Sum * f g) 
type Rep (Sum k f g a) 

newtype Identity a :: * -> * #

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

Since: 4.8.0.0

Constructors

Identity 

Fields

Instances

Monad Identity 

Methods

(>>=) :: Identity a -> (a -> Identity b) -> Identity b #

(>>) :: Identity a -> Identity b -> Identity b #

return :: a -> Identity a #

fail :: String -> Identity a #

Functor Identity 

Methods

fmap :: (a -> b) -> Identity a -> Identity b #

(<$) :: a -> Identity b -> Identity a #

MonadFix Identity 

Methods

mfix :: (a -> Identity a) -> Identity a #

Applicative Identity 

Methods

pure :: a -> Identity a #

(<*>) :: Identity (a -> b) -> Identity a -> Identity b #

(*>) :: Identity a -> Identity b -> Identity b #

(<*) :: Identity a -> Identity b -> Identity a #

Foldable Identity 

Methods

fold :: Monoid m => Identity m -> m #

foldMap :: Monoid m => (a -> m) -> Identity a -> m #

foldr :: (a -> b -> b) -> b -> Identity a -> b #

foldr' :: (a -> b -> b) -> b -> Identity a -> b #

foldl :: (b -> a -> b) -> b -> Identity a -> b #

foldl' :: (b -> a -> b) -> b -> Identity a -> b #

foldr1 :: (a -> a -> a) -> Identity a -> a #

foldl1 :: (a -> a -> a) -> Identity a -> a #

toList :: Identity a -> [a] #

null :: Identity a -> Bool #

length :: Identity a -> Int #

elem :: Eq a => a -> Identity a -> Bool #

maximum :: Ord a => Identity a -> a #

minimum :: Ord a => Identity a -> a #

sum :: Num a => Identity a -> a #

product :: Num a => Identity a -> a #

Traversable Identity 

Methods

traverse :: Applicative f => (a -> f b) -> Identity a -> f (Identity b) #

sequenceA :: Applicative f => Identity (f a) -> f (Identity a) #

mapM :: Monad m => (a -> m b) -> Identity a -> m (Identity b) #

sequence :: Monad m => Identity (m a) -> m (Identity a) #

Generic1 Identity 

Associated Types

type Rep1 (Identity :: * -> *) :: * -> * #

Methods

from1 :: Identity a -> Rep1 Identity a #

to1 :: Rep1 Identity a -> Identity a #

Eq1 Identity 

Methods

liftEq :: (a -> b -> Bool) -> Identity a -> Identity b -> Bool #

Ord1 Identity 

Methods

liftCompare :: (a -> b -> Ordering) -> Identity a -> Identity b -> Ordering #

Read1 Identity 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Identity a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Identity a] #

Show1 Identity 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Identity a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Identity a] -> ShowS #

MonadZip Identity 

Methods

mzip :: Identity a -> Identity b -> Identity (a, b) #

mzipWith :: (a -> b -> c) -> Identity a -> Identity b -> Identity c #

munzip :: Identity (a, b) -> (Identity a, Identity b) #

MonadBase Identity Identity 

Methods

liftBase :: Identity α -> Identity α #

MonadBaseControl Identity Identity 

Associated Types

type StM (Identity :: * -> *) a :: * #

Bounded a => Bounded (Identity a) 
Enum a => Enum (Identity a) 
Eq a => Eq (Identity a) 

Methods

(==) :: Identity a -> Identity a -> Bool #

(/=) :: Identity a -> Identity a -> Bool #

Floating a => Floating (Identity a) 
Fractional a => Fractional (Identity a) 
Integral a => Integral (Identity a) 
Data a => Data (Identity a) 

Methods

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

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

toConstr :: Identity a -> Constr #

dataTypeOf :: Identity a -> DataType #

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

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

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

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

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

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

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

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

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

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

Num a => Num (Identity a) 
Ord a => Ord (Identity a) 

Methods

compare :: Identity a -> Identity a -> Ordering #

(<) :: Identity a -> Identity a -> Bool #

(<=) :: Identity a -> Identity a -> Bool #

(>) :: Identity a -> Identity a -> Bool #

(>=) :: Identity a -> Identity a -> Bool #

max :: Identity a -> Identity a -> Identity a #

min :: Identity a -> Identity a -> Identity a #

Read a => Read (Identity a)

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

Real a => Real (Identity a) 

Methods

toRational :: Identity a -> Rational #

RealFloat a => RealFloat (Identity a) 
RealFrac a => RealFrac (Identity a) 

Methods

properFraction :: Integral b => Identity a -> (b, Identity a) #

truncate :: Integral b => Identity a -> b #

round :: Integral b => Identity a -> b #

ceiling :: Integral b => Identity a -> b #

floor :: Integral b => Identity a -> b #

Show a => Show (Identity a)

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

Methods

showsPrec :: Int -> Identity a -> ShowS #

show :: Identity a -> String #

showList :: [Identity a] -> ShowS #

Ix a => Ix (Identity a) 
IsString a => IsString (Identity a) 

Methods

fromString :: String -> Identity a #

Generic (Identity a) 

Associated Types

type Rep (Identity a) :: * -> * #

Methods

from :: Identity a -> Rep (Identity a) x #

to :: Rep (Identity a) x -> Identity a #

Semigroup a => Semigroup (Identity a) 

Methods

(<>) :: Identity a -> Identity a -> Identity a #

sconcat :: NonEmpty (Identity a) -> Identity a #

stimes :: Integral b => b -> Identity a -> Identity a #

Monoid a => Monoid (Identity a) 

Methods

mempty :: Identity a #

mappend :: Identity a -> Identity a -> Identity a #

mconcat :: [Identity a] -> Identity a #

Storable a => Storable (Identity a) 

Methods

sizeOf :: Identity a -> Int #

alignment :: Identity a -> Int #

peekElemOff :: Ptr (Identity a) -> Int -> IO (Identity a) #

pokeElemOff :: Ptr (Identity a) -> Int -> Identity a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Identity a) #

pokeByteOff :: Ptr b -> Int -> Identity a -> IO () #

peek :: Ptr (Identity a) -> IO (Identity a) #

poke :: Ptr (Identity a) -> Identity a -> IO () #

Bits a => Bits (Identity a) 
FiniteBits a => FiniteBits (Identity a) 
type Rep1 Identity 
type Rep1 Identity = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))
type StM Identity a 
type StM Identity a = a
type Rep (Identity a) 
type Rep (Identity a) = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

class Applicative f => Alternative f where #

A monoid on applicative functors.

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

  • some v = (:) <$> v <*> many v
  • many v = some v <|> pure []

Minimal complete definition

empty, (<|>)

Instances

Alternative [] 

Methods

empty :: [a] #

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

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

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

Alternative Maybe 

Methods

empty :: Maybe a #

(<|>) :: Maybe a -> Maybe a -> Maybe a #

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

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

Alternative IO 

Methods

empty :: IO a #

(<|>) :: IO a -> IO a -> IO a #

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

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

Alternative U1 

Methods

empty :: U1 a #

(<|>) :: U1 a -> U1 a -> U1 a #

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

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

Alternative P 

Methods

empty :: P a #

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

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

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

Alternative Option 

Methods

empty :: Option a #

(<|>) :: Option a -> Option a -> Option a #

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

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

Alternative STM 

Methods

empty :: STM a #

(<|>) :: STM a -> STM a -> STM a #

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

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

Alternative ReadPrec 

Methods

empty :: ReadPrec a #

(<|>) :: ReadPrec a -> ReadPrec a -> ReadPrec a #

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

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

Alternative ReadP 

Methods

empty :: ReadP a #

(<|>) :: ReadP a -> ReadP a -> ReadP a #

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

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

Alternative Seq 

Methods

empty :: Seq a #

(<|>) :: Seq a -> Seq a -> Seq a #

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

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

Alternative f => Alternative (Rec1 f) 

Methods

empty :: Rec1 f a #

(<|>) :: Rec1 f a -> Rec1 f a -> Rec1 f a #

some :: Rec1 f a -> Rec1 f [a] #

many :: Rec1 f a -> Rec1 f [a] #

MonadPlus m => Alternative (WrappedMonad m) 

Methods

empty :: WrappedMonad m a #

(<|>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a #

some :: WrappedMonad m a -> WrappedMonad m [a] #

many :: WrappedMonad m a -> WrappedMonad m [a] #

ArrowPlus a => Alternative (ArrowMonad a) 

Methods

empty :: ArrowMonad a a #

(<|>) :: ArrowMonad a a -> ArrowMonad a a -> ArrowMonad a a #

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

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

Alternative (Proxy *) 

Methods

empty :: Proxy * a #

(<|>) :: Proxy * a -> Proxy * a -> Proxy * a #

some :: Proxy * a -> Proxy * [a] #

many :: Proxy * a -> Proxy * [a] #

Applicative m => Alternative (ListT m) 

Methods

empty :: ListT m a #

(<|>) :: ListT m a -> ListT m a -> ListT m a #

some :: ListT m a -> ListT m [a] #

many :: ListT m a -> ListT m [a] #

Alternative m => Alternative (ResourceT m)

Since 1.1.5

Methods

empty :: ResourceT m a #

(<|>) :: ResourceT m a -> ResourceT m a -> ResourceT m a #

some :: ResourceT m a -> ResourceT m [a] #

many :: ResourceT m a -> ResourceT m [a] #

Alternative f => Alternative (Lift f)

A combination is Pure only either part is.

Methods

empty :: Lift f a #

(<|>) :: Lift f a -> Lift f a -> Lift f a #

some :: Lift f a -> Lift f [a] #

many :: Lift f a -> Lift f [a] #

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

Methods

empty :: MaybeT m a #

(<|>) :: MaybeT m a -> MaybeT m a -> MaybeT m a #

some :: MaybeT m a -> MaybeT m [a] #

many :: MaybeT m a -> MaybeT m [a] #

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

Methods

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

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

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

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

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

Methods

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

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

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

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

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

Methods

empty :: WrappedArrow a b a #

(<|>) :: WrappedArrow a b a -> WrappedArrow a b a -> WrappedArrow a b a #

some :: WrappedArrow a b a -> WrappedArrow a b [a] #

many :: WrappedArrow a b a -> WrappedArrow a b [a] #

Alternative f => Alternative (Alt * f) 

Methods

empty :: Alt * f a #

(<|>) :: Alt * f a -> Alt * f a -> Alt * f a #

some :: Alt * f a -> Alt * f [a] #

many :: Alt * f a -> Alt * f [a] #

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

Methods

empty :: ExceptT e m a #

(<|>) :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

some :: ExceptT e m a -> ExceptT e m [a] #

many :: ExceptT e m a -> ExceptT e m [a] #

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

Methods

empty :: ErrorT e m a #

(<|>) :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a #

some :: ErrorT e m a -> ErrorT e m [a] #

many :: ErrorT e m a -> ErrorT e m [a] #

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

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

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

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

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

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

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

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

Alternative f => Alternative (Backwards * f)

Try alternatives in the same order as f.

Methods

empty :: Backwards * f a #

(<|>) :: Backwards * f a -> Backwards * f a -> Backwards * f a #

some :: Backwards * f a -> Backwards * f [a] #

many :: Backwards * f a -> Backwards * f [a] #

Alternative m => Alternative (IdentityT * m) 

Methods

empty :: IdentityT * m a #

(<|>) :: IdentityT * m a -> IdentityT * m a -> IdentityT * m a #

some :: IdentityT * m a -> IdentityT * m [a] #

many :: IdentityT * m a -> IdentityT * m [a] #

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

The Alternative instance glues streams together stepwise.

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

See also never, untilJust and delays

Methods

empty :: Stream f m a #

(<|>) :: Stream f m a -> Stream f m a -> Stream f m a #

some :: Stream f m a -> Stream f m [a] #

many :: Stream f m a -> Stream f m [a] #

Alternative f => Alternative (M1 i c f) 

Methods

empty :: M1 i c f a #

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

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

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

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

Methods

empty :: Product * f g a #

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

some :: Product * f g a -> Product * f g [a] #

many :: Product * f g a -> Product * f g [a] #

Alternative m => Alternative (ReaderT * r m) 

Methods

empty :: ReaderT * r m a #

(<|>) :: ReaderT * r m a -> ReaderT * r m a -> ReaderT * r m a #

some :: ReaderT * r m a -> ReaderT * r m [a] #

many :: ReaderT * r m a -> ReaderT * r m [a] #

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

Methods

empty :: Compose * * f g a #

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

some :: Compose * * f g a -> Compose * * f g [a] #

many :: Compose * * f g a -> Compose * * f g [a] #

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

Methods

empty :: RWST r w s m a #

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

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

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

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

Methods

empty :: RWST r w s m a #

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

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

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

class Monad m => MonadThrow m where #

A class for monads in which exceptions may be thrown.

Instances should obey the following law:

throwM e >> x = throwM e

In other words, throwing an exception short-circuits the rest of the monadic computation.

Instances

MonadThrow [] 

Methods

throwM :: Exception e => e -> [a] #

MonadThrow Maybe 

Methods

throwM :: Exception e => e -> Maybe a #

MonadThrow IO 

Methods

throwM :: Exception e => e -> IO a #

MonadThrow Q 

Methods

throwM :: Exception e => e -> Q a #

MonadThrow STM 

Methods

throwM :: Exception e => e -> STM a #

(~) * e SomeException => MonadThrow (Either e) 

Methods

throwM :: Exception e => e -> Either e a #

MonadThrow m => MonadThrow (ListT m) 

Methods

throwM :: Exception e => e -> ListT m a #

MonadThrow m => MonadThrow (ResourceT m) 

Methods

throwM :: Exception e => e -> ResourceT m a #

MonadThrow m => MonadThrow (MaybeT m)

Throws exceptions into the base monad.

Methods

throwM :: Exception e => e -> MaybeT m a #

MonadThrow m => MonadThrow (ExceptT e m)

Throws exceptions into the base monad.

Methods

throwM :: Exception e => e -> ExceptT e m a #

(Error e, MonadThrow m) => MonadThrow (ErrorT e m)

Throws exceptions into the base monad.

Methods

throwM :: Exception e => e -> ErrorT e m a #

MonadThrow m => MonadThrow (StateT s m) 

Methods

throwM :: Exception e => e -> StateT s m a #

MonadThrow m => MonadThrow (StateT s m) 

Methods

throwM :: Exception e => e -> StateT s m a #

(MonadThrow m, Monoid w) => MonadThrow (WriterT w m) 

Methods

throwM :: Exception e => e -> WriterT w m a #

(MonadThrow m, Monoid w) => MonadThrow (WriterT w m) 

Methods

throwM :: Exception e => e -> WriterT w m a #

MonadThrow m => MonadThrow (IdentityT * m) 

Methods

throwM :: Exception e => e -> IdentityT * m a #

(MonadThrow m, Functor f) => MonadThrow (Stream f m) # 

Methods

throwM :: Exception e => e -> Stream f m a #

MonadThrow m => MonadThrow (ContT * r m) 

Methods

throwM :: Exception e => e -> ContT * r m a #

MonadThrow m => MonadThrow (ReaderT * r m) 

Methods

throwM :: Exception e => e -> ReaderT * r m a #

(MonadThrow m, Monoid w) => MonadThrow (RWST r w s m) 

Methods

throwM :: Exception e => e -> RWST r w s m a #

(MonadThrow m, Monoid w) => MonadThrow (RWST r w s m) 

Methods

throwM :: Exception e => e -> RWST r w s m a #

class (MonadThrow m, MonadIO m, Applicative m, MonadBase IO m) => MonadResource m where #

A Monad which allows for safe resource allocation. In theory, any monad transformer stack which includes a ResourceT can be an instance of MonadResource.

Note: runResourceT has a requirement for a MonadBaseControl IO m monad, which allows control operations to be lifted. A MonadResource does not have this requirement. This means that transformers such as ContT can be an instance of MonadResource. However, the ContT wrapper will need to be unwrapped before calling runResourceT.

Since 0.3.0

Instances

MonadResource m => MonadResource (ListT m) 

Methods

liftResourceT :: ResourceT IO a -> ListT m a #

(MonadThrow m, MonadBase IO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) 

Methods

liftResourceT :: ResourceT IO a -> ResourceT m a #

MonadResource m => MonadResource (MaybeT m) 

Methods

liftResourceT :: ResourceT IO a -> MaybeT m a #

MonadResource m => MonadResource (ExceptT e m) 

Methods

liftResourceT :: ResourceT IO a -> ExceptT e m a #

(Error e, MonadResource m) => MonadResource (ErrorT e m) 

Methods

liftResourceT :: ResourceT IO a -> ErrorT e m a #

MonadResource m => MonadResource (StateT s m) 

Methods

liftResourceT :: ResourceT IO a -> StateT s m a #

MonadResource m => MonadResource (StateT s m) 

Methods

liftResourceT :: ResourceT IO a -> StateT s m a #

(Monoid w, MonadResource m) => MonadResource (WriterT w m) 

Methods

liftResourceT :: ResourceT IO a -> WriterT w m a #

(Monoid w, MonadResource m) => MonadResource (WriterT w m) 

Methods

liftResourceT :: ResourceT IO a -> WriterT w m a #

MonadResource m => MonadResource (IdentityT * m) 

Methods

liftResourceT :: ResourceT IO a -> IdentityT * m a #

(MonadResource m, Functor f) => MonadResource (Stream f m) # 

Methods

liftResourceT :: ResourceT IO a -> Stream f m a #

MonadResource m => MonadResource (ContT * r m) 

Methods

liftResourceT :: ResourceT IO a -> ContT * r m a #

MonadResource m => MonadResource (ReaderT * r m) 

Methods

liftResourceT :: ResourceT IO a -> ReaderT * r m a #

(Monoid w, MonadResource m) => MonadResource (RWST r w s m) 

Methods

liftResourceT :: ResourceT IO a -> RWST r w s m a #

(Monoid w, MonadResource m) => MonadResource (RWST r w s m) 

Methods

liftResourceT :: ResourceT IO a -> RWST r w s m a #

class (Applicative b, Applicative m, Monad b, Monad m) => MonadBase b m | m -> b where #

Instances

MonadBase [] [] 

Methods

liftBase :: [α] -> [α] #

MonadBase Maybe Maybe 

Methods

liftBase :: Maybe α -> Maybe α #

MonadBase IO IO 

Methods

liftBase :: IO α -> IO α #

MonadBase Identity Identity 

Methods

liftBase :: Identity α -> Identity α #

MonadBase STM STM 

Methods

liftBase :: STM α -> STM α #

MonadBase b m => MonadBase b (ResourceT m) 

Methods

liftBase :: b α -> ResourceT m α #

MonadBase b m => MonadBase b (MaybeT m) 

Methods

liftBase :: b α -> MaybeT m α #

MonadBase b m => MonadBase b (ListT m) 

Methods

liftBase :: b α -> ListT m α #

(Monoid w, MonadBase b m) => MonadBase b (WriterT w m) 

Methods

liftBase :: b α -> WriterT w m α #

(Monoid w, MonadBase b m) => MonadBase b (WriterT w m) 

Methods

liftBase :: b α -> WriterT w m α #

MonadBase b m => MonadBase b (StateT s m) 

Methods

liftBase :: b α -> StateT s m α #

MonadBase b m => MonadBase b (StateT s m) 

Methods

liftBase :: b α -> StateT s m α #

MonadBase b m => MonadBase b (IdentityT * m) 

Methods

liftBase :: b α -> IdentityT * m α #

MonadBase b m => MonadBase b (ExceptT e m) 

Methods

liftBase :: b α -> ExceptT e m α #

(Error e, MonadBase b m) => MonadBase b (ErrorT e m) 

Methods

liftBase :: b α -> ErrorT e m α #

(MonadBase b m, Functor f) => MonadBase b (Stream f m) # 

Methods

liftBase :: b α -> Stream f m α #

MonadBase b m => MonadBase b (ReaderT * r m) 

Methods

liftBase :: b α -> ReaderT * r m α #

MonadBase b m => MonadBase b (ContT * r m) 

Methods

liftBase :: b α -> ContT * r m α #

(Monoid w, MonadBase b m) => MonadBase b (RWST r w s m) 

Methods

liftBase :: b α -> RWST r w s m α #

(Monoid w, MonadBase b m) => MonadBase b (RWST r w s m) 

Methods

liftBase :: b α -> RWST r w s m α #

MonadBase ((->) r) ((->) r) 

Methods

liftBase :: (r -> α) -> r -> α #

MonadBase (Either e) (Either e) 

Methods

liftBase :: Either e α -> Either e α #

MonadBase (ST s) (ST s) 

Methods

liftBase :: ST s α -> ST s α #

MonadBase (ST s) (ST s) 

Methods

liftBase :: ST s α -> ST s α #

data ResourceT m a :: (* -> *) -> * -> * #

The Resource transformer. This transformer keeps track of all registered actions, and calls them upon exit (via runResourceT). Actions may be registered via register, or resources may be allocated atomically via allocate. allocate corresponds closely to bracket.

Releasing may be performed before exit via the release function. This is a highly recommended optimization, as it will ensure that scarce resources are freed early. Note that calling release will deregister the action, so that a release action will only ever be called once.

Since 0.3.0

Instances

MFunctor ResourceT

Since 0.4.7

Methods

hoist :: Monad m => (forall a. m a -> n a) -> ResourceT m b -> ResourceT n b #

MMonad ResourceT

Since 0.4.7

Methods

embed :: Monad n => (forall a. m a -> ResourceT n a) -> ResourceT m b -> ResourceT n b #

MonadTrans ResourceT 

Methods

lift :: Monad m => m a -> ResourceT m a #

MonadTransControl ResourceT 

Associated Types

type StT (ResourceT :: (* -> *) -> * -> *) a :: * #

Methods

liftWith :: Monad m => (Run ResourceT -> m a) -> ResourceT m a #

restoreT :: Monad m => m (StT ResourceT a) -> ResourceT m a #

MonadRWS r w s m => MonadRWS r w s (ResourceT m) 
MonadBase b m => MonadBase b (ResourceT m) 

Methods

liftBase :: b α -> ResourceT m α #

MonadBaseControl b m => MonadBaseControl b (ResourceT m) 

Associated Types

type StM (ResourceT m :: * -> *) a :: * #

Methods

liftBaseWith :: (RunInBase (ResourceT m) b -> b a) -> ResourceT m a #

restoreM :: StM (ResourceT m) a -> ResourceT m a #

MonadError e m => MonadError e (ResourceT m) 

Methods

throwError :: e -> ResourceT m a #

catchError :: ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a #

MonadReader r m => MonadReader r (ResourceT m) 

Methods

ask :: ResourceT m r #

local :: (r -> r) -> ResourceT m a -> ResourceT m a #

reader :: (r -> a) -> ResourceT m a #

MonadState s m => MonadState s (ResourceT m) 

Methods

get :: ResourceT m s #

put :: s -> ResourceT m () #

state :: (s -> (a, s)) -> ResourceT m a #

MonadWriter w m => MonadWriter w (ResourceT m) 

Methods

writer :: (a, w) -> ResourceT m a #

tell :: w -> ResourceT m () #

listen :: ResourceT m a -> ResourceT m (a, w) #

pass :: ResourceT m (a, w -> w) -> ResourceT m a #

Monad m => Monad (ResourceT m) 

Methods

(>>=) :: ResourceT m a -> (a -> ResourceT m b) -> ResourceT m b #

(>>) :: ResourceT m a -> ResourceT m b -> ResourceT m b #

return :: a -> ResourceT m a #

fail :: String -> ResourceT m a #

Functor m => Functor (ResourceT m) 

Methods

fmap :: (a -> b) -> ResourceT m a -> ResourceT m b #

(<$) :: a -> ResourceT m b -> ResourceT m a #

MonadFix m => MonadFix (ResourceT m)

Since: 1.1.8

Methods

mfix :: (a -> ResourceT m a) -> ResourceT m a #

Applicative m => Applicative (ResourceT m) 

Methods

pure :: a -> ResourceT m a #

(<*>) :: ResourceT m (a -> b) -> ResourceT m a -> ResourceT m b #

(*>) :: ResourceT m a -> ResourceT m b -> ResourceT m b #

(<*) :: ResourceT m a -> ResourceT m b -> ResourceT m a #

MonadIO m => MonadIO (ResourceT m) 

Methods

liftIO :: IO a -> ResourceT m a #

Alternative m => Alternative (ResourceT m)

Since 1.1.5

Methods

empty :: ResourceT m a #

(<|>) :: ResourceT m a -> ResourceT m a -> ResourceT m a #

some :: ResourceT m a -> ResourceT m [a] #

many :: ResourceT m a -> ResourceT m [a] #

MonadPlus m => MonadPlus (ResourceT m)

Since 1.1.5

Methods

mzero :: ResourceT m a #

mplus :: ResourceT m a -> ResourceT m a -> ResourceT m a #

MonadThrow m => MonadThrow (ResourceT m) 

Methods

throwM :: Exception e => e -> ResourceT m a #

MonadCatch m => MonadCatch (ResourceT m) 

Methods

catch :: Exception e => ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a #

MonadMask m => MonadMask (ResourceT m) 

Methods

mask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b #

uninterruptibleMask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b #

MonadCont m => MonadCont (ResourceT m) 

Methods

callCC :: ((a -> ResourceT m b) -> ResourceT m a) -> ResourceT m a #

(MonadThrow m, MonadBase IO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) 

Methods

liftResourceT :: ResourceT IO a -> ResourceT m a #

type StT ResourceT a 
type StT ResourceT a = a
type StM (ResourceT m) a 
type StM (ResourceT m) a = StM m a

runResourceT :: MonadBaseControl IO m => ResourceT m a -> m a #

Unwrap a ResourceT transformer, and call all registered release actions.

Note that there is some reference counting involved due to resourceForkIO. If multiple threads are sharing the same collection of resources, only the last call to runResourceT will deallocate the resources.

Since 0.3.0

class Bifunctor p where #

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: 4.8.0.0

Minimal complete definition

bimap | first, second

Instances

Bifunctor Either 

Methods

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

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

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

Bifunctor (,) 

Methods

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

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

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

Bifunctor Arg 

Methods

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

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

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

Bifunctor Of # 

Methods

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

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

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

Bifunctor (K1 i) 

Methods

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

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

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

Bifunctor ((,,) x1) 

Methods

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

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

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

Bifunctor (Const *) 

Methods

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

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

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

Bifunctor ((,,,) x1 x2) 

Methods

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

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

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

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

Methods

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

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

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

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

Methods

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

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

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

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

Methods

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

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

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

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

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.

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

Promote a function to a monad.

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

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 #

Lift a binary function to actions.

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

Lift a ternary function to actions.

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

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

Examples

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

(<>) :: Monoid m => m -> m -> m infixr 6 #

An infix synonym for mappend.

Since: 4.5.0.0