HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleio-streams-1.5.2.2Haskell2010

System.IO.Streams.Internal

Internal implementation of the io-streams library, intended for library writers

Library users should use the interface provided by System.IO.Streams

  • 6 types
  • 22 values

Types

2 declarations

About pushback

0 declarations

Users can push a value back into an input stream using the unRead function. Usually this will use the default pushback mechanism which provides a buffer for the stream. Some stream transformers, like takeBytes, produce streams that send pushed-back values back to the streams that they wrap. A function like map cannot do this because the types don't match up:

map :: (a -> b) -> InputStream a -> IO (InputStream b)

A function will usually document if its pushback behaviour differs from the default. No matter what the case, input streams should obey the following law:

Streams.unRead c stream >> Streams.read stream === return (Just c)

Input and output streams

2 declarations
datadata InputStream a
#

An InputStream generates values of type c in the IO monad.

Two primitive operations are defined on InputStream:

It is intended that InputStreams obey the following law:

unRead c stream >> read stream === return (Just c)

Constructors

Instances6BufferedIO, RawIO, IODevice
datadata OutputStream a
#

An OutputStream consumes values of type c in the IO monad. The only primitive operation defined on OutputStream is:

Values of type c are written in an OutputStream by wrapping them in Just, and the end of the stream is indicated by supplying Nothing.

If you supply a value after a Nothing, the behavior is defined by the implementer of the given OutputStream. (All OutputStream definitions in this library will simply discard the extra input.)

Constructors

Instances6BufferedIO, RawIO, IODevice

Primitive stream operations

6 declarations
valueunRead :: a -> InputStream a -> IO ()
#

Pushes a value back onto an input stream. read and unRead should satisfy the following law, with the possible exception of side effects:

Streams.unRead c stream >> Streams.read stream === return (Just c)

Note that this could be used to add values back to the stream that were not originally drawn from the stream.

Building streams

4 declarations
valuemakeInputStream :: IO (Maybe a) -> IO (InputStream a)
#

Creates an InputStream from a value-producing action.

(makeInputStream m) calls the action m each time you request a value from the InputStream. The given action is extended with the default pushback mechanism (see System.IO.Streams.Internal#pushback).

valuemakeOutputStream :: (Maybe a -> IO ()) -> IO (OutputStream a)
#

Creates an OutputStream from a value-consuming action.

(makeOutputStream f) runs the computation f on each value fed to it.

Since version 1.2.0.0, makeOutputStream also ensures that output streams no longer receive data once EOF is received (i.e. you can now assume that makeOutputStream will feed your function Nothing at most once.)

Connecting streams

4 declarations

Thread safety

2 declarations

Converts an InputStream into a thread-safe InputStream, at a slight performance penalty.

For performance reasons, this library provides non-thread-safe streams by default. Use the locking functions to convert these streams into slightly slower, but thread-safe, equivalents.

Utility streams

2 declarations

Generator monad

3 declarations
newtypenewtype Generator r a
#

A Generator is a coroutine monad that can be used to define complex InputStreams. You can cause a value of type Just r to appear when the InputStream is read by calling yield:

g :: Generator Int ()
g = do
    Streams.yield 1
    Streams.yield 2
    Streams.yield 3

A Generator can be turned into an InputStream by calling fromGenerator:

m :: IO [Int]
m = Streams.fromGenerator g >>= Streams.System.IO.Streams.toList     -- value returned is [1,2,3]

You can perform IO by calling liftIO, and turn a Generator into an InputStream with fromGenerator.

As a general rule, you should not acquire resources that need to be freed from a Generator, because there is no guarantee the coroutine continuation will ever be called, nor can you catch an exception from within a Generator.

Instances4Monad, Functor, Applicative, MonadIO

Consumer monad

3 declarations
newtypenewtype Consumer c a
#
Instances4Monad, Functor, Applicative, MonadIO
  • Monad (Consumer c)Defined in io-streams-1.5.2.2 · System.IO.Streams.Internal
  • Functor (Consumer r)Defined in io-streams-1.5.2.2 · System.IO.Streams.Internal
  • Applicative (Consumer r)Defined in io-streams-1.5.2.2 · System.IO.Streams.Internal
  • MonadIO (Consumer c)Defined in io-streams-1.5.2.2 · System.IO.Streams.Internal