| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Meter
Description
Performance measurement reimagined as a Circuit.
A Meter arr a b is a pair of arrows: start produces the initial
state, stop observes it and produces a measurement. The canonical
use is meterAction, which sandwiches a payload arrow between the
two meter arrows.
Synopsis
- data Meter (arr :: Type -> Type -> Type) a b = Meter {}
- mkMeter :: m a -> (a -> m b) -> Meter (K m) a b
- firstK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (a, c) (b, c)
- secondK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (c, a) (c, b)
- dimapK :: forall (m :: Type -> Type) a' a b b'. Functor m => (a' -> a) -> (b -> b') -> K m a b -> K m a' b'
- both :: forall (m :: Type -> Type) a1 b1 a2 b2. Monad m => Meter (K m) a1 b1 -> Meter (K m) a2 b2 -> Meter (K m) (a1, a2) (b1, b2)
- meterAction :: forall (m :: Type -> Type) a b c d (t :: Type -> Type -> Type). Monad m => Meter (K m) a b -> K m c d -> Trace t (K m) c (b, d)
- hold :: a -> a
Meter
data Meter (arr :: Type -> Type -> Type) a b Source #
A Meter arr a b is a stopwatch: a pair of arrows.
Cartesian helpers for Kleisli arrows
firstK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (a, c) (b, c) Source #
First component for K m.
secondK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (c, a) (c, b) Source #
Second component for K m.
dimapK :: forall (m :: Type -> Type) a' a b b'. Functor m => (a' -> a) -> (b -> b') -> K m a b -> K m a' b' Source #
Profunctor-style pre/post composition for K m.
Meter composition
both :: forall (m :: Type -> Type) a1 b1 a2 b2. Monad m => Meter (K m) a1 b1 -> Meter (K m) a2 b2 -> Meter (K m) (a1, a2) (b1, b2) Source #
Run two meters simultaneously.
The state wires are independent; the (,) tensor handles the
wiring automatically.
Plugin metering
meterAction :: forall (m :: Type -> Type) a b c d (t :: Type -> Type -> Type). Monad m => Meter (K m) a b -> K m c d -> Trace t (K m) c (b, d) Source #
Meter a Kleisli arrow action, keeping the measurement.
Tensor-agnostic: the bracket is built directly in the base arrow
and lifted with base, so the meter state is introduced and consumed
locally. The result is a Circuit polymorphic in the tensor t.
For arrow-level extraction, use eval with your chosen tensor.