HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulefs-sim-0.5.0.1Haskell2010

System.FS.Sim.Stream

Finite and infinite streams of Maybe as.

  • 2 types
  • 18 values
  • Packagefs-sim-0.5.0.1
  • Exports20
  • LanguageHaskell2010
  • LicenceApache-2.0
  • SourceStream.hs

Streams

2 declarations
datadata Stream a
#

A stream of Maybe as that can be infinite.

Constructors

  • UnsafeStream

    UNSAFE: when constructing, modifying, or accessing the internals of a Stream, it is the responsibility of the user to preserve the following invariant:

    INVARIANT: if the stream is marked as Infinite, then the internal list should be infinite. If the stream is marked as Finite, then the internal list should finite.

    • If the internal list is infinite but marked as Finite, then shrink or show on the corresponding stream will diverge.

    • If the internal list is finite but marked as Infinite, then shrink on the corresponding stream will degrade to an infinite list of empty streams.

Instances2Functor, Show
  • Functor StreamDefined in fs-sim-0.5.0.1 · System.FS.Sim.Stream
  • Show a => Show (Stream a)Defined in fs-sim-0.5.0.1 · System.FS.Sim.Stream

    Fully shows a Stream if it is finite, or prints a placeholder string if it is infinite.

Running

3 declarations
valuerunStreamIndefinitely :: Stream a -> [Maybe a]
#

O(\infty) : like runStream, but advancing the stream indefinitely.

For infinite streams, this produces an infinite list. For finite streams, this produces a finite list.

Construction

5 declarations

Modify

1 declaration

Query

3 declarations
valuenull :: Stream a -> Bool
#

Check that the stream is empty.

In general, a stream is only empty if the stream is equivalent to empty.

A finite/infinite stream consisting of only Nothings is not considered to be empty. In particular, null (always Nothing) /= True.

Generation and shrinking

6 declarations
valuegenMaybe
  1. :: Int

    Likelihood of Nothing

  2. -> Int

    Likelihood of Just a

  3. -> Gen a
  4. -> Gen (Maybe a)
#

Make a Maybe a generator based on an a generator.

Each element has a chance of being either Nothing or an element generated with the given a generator (wrapped in a Just). These likelihoods are passed to frequency.

valueshrinkStream :: Stream a -> [Stream a]
#

Shrink a stream like it is an InfiniteList.

Infinite streams are shrunk differently than lists that are finite, which is to ensure that we shrink infinite lists towards finite lists.

  • Infinite streams are shrunk by taking finite prefixes of the argument stream. Note that there are an infinite number of finite prefixes, so even though the *shrink list* is infinite, the individual *list elements* are finite.

  • Finite streams are shrunk like lists are shrunk normally, preserving finiteness.