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

Modulecapability-0.5.0.1Haskell2010

Capability.Sink

Defines a capability for computations that produce a stream of values as part of their execution.

Programs producing streams of data are common. Examples: emitting events on input, or emitting events whenever certain conditions are observed. streams are similar to Python generators.

The HasSink capability enables separating the logic responsible for emitting events from that responsible for collecting or handling them. The name is because a sink is needed to consume the locally produced stream.

This can be thought of as a writer capability of a list of values HasWriter tag [v] with \x -> tell @tag [x] as a primitive operation. However, that implementation would be inefficient.

For example using the Streaming.Prelude.Stream instance, a producer defined using this capability can be consumed efficiently in a streaming fashion.

  • 1 type

Relational capability

0 declarations

Functional capability

2 declarations
typetype HasSink' (tag :: k) = HasSink tag (TypeOf k tag)
#

Type synonym using the TypeOf type family to specify HasSink constraints without having to specify the type associated to a tag.

familytype family TypeOf k (s :: k)
#

Type family associating a tag to the corresponding type. It is intended to simplify constraint declarations, by removing the need to redundantly specify the type associated to a tag.

It is poly-kinded, which allows users to define their own kind of tags. Standard haskell types can also be used as tags by specifying the Type kind when defining the type family instance.

Defining TypeOf instances for GHC.TypeLits.Symbols (typelevel string literals) is discouraged. Since symbols all belong to the same global namespace, such instances could conflict with others defined in external libraries. More generally, as for typeclasses, TypeOf instances should always be defined in the same module as the tag type to prevent issues due to orphan instances.

Example:

    import Capability.Reader

    data Foo
    data Bar
    type instance TypeOf Type Foo = Int
    type instance TypeOf Type Bar = String

    -- Same as: foo :: HasReader Foo Int M => …
    foo :: HasReader' Foo m => …
    foo = …

Strategies

0 declarations

Modifiers