Skuld.Comp.ScopeEnv (skuld v0.30.0)

View Source

Scope machinery carried through a computation.

Groups the three elements that define what scope a computation is running in:

  • evidence — installed effect handlers
  • leave_scope — cleanup chain for scoped effects
  • transform_suspend — suspend decoration chain, also scoped

These three are installed together via scoped/2, inherited together at fiber spawn, and survive suspend/resume cycles together. They are the computation's "scope structure" — the runtime context that determines how effects are handled.

Relationship with Env

ScopeEnv is embedded in Env.scope. The Env module provides accessor functions that delegate into scope so callers don't need to reach through the nesting to read or mutate scope fields directly.

Summary

Functions

Remove a handler for an effect signature

Get the handler for an effect signature, or nil

Get the current leave-scope handler (returns identity if nil)

Get the current transform-suspend handler (returns identity if nil)

Get all installed handler signatures

Create a fresh scope env with identity leave_scope and transform_suspend

Install a handler for an effect signature

Install a new leave-scope handler

Install a new transform-suspend handler

Types

t()

@type t() :: %Skuld.Comp.ScopeEnv{
  evidence: %{required(Skuld.Comp.Types.sig()) => Skuld.Comp.Types.handler()},
  leave_scope: Skuld.Comp.Types.leave_scope() | nil,
  transform_suspend: Skuld.Comp.Types.transform_suspend() | nil
}

Functions

delete_handler(scope, sig)

@spec delete_handler(t(), Skuld.Comp.Types.sig()) :: t()

Remove a handler for an effect signature

get_handler(scope, sig)

@spec get_handler(t(), Skuld.Comp.Types.sig()) :: Skuld.Comp.Types.handler() | nil

Get the handler for an effect signature, or nil

get_leave_scope(scope)

@spec get_leave_scope(t()) :: Skuld.Comp.Types.leave_scope()

Get the current leave-scope handler (returns identity if nil)

get_transform_suspend(scope)

@spec get_transform_suspend(t()) :: Skuld.Comp.Types.transform_suspend()

Get the current transform-suspend handler (returns identity if nil)

handler_sigs(scope)

@spec handler_sigs(t()) :: [Skuld.Comp.Types.sig()]

Get all installed handler signatures

new()

@spec new() :: t()

Create a fresh scope env with identity leave_scope and transform_suspend

put_handler(scope, sig, handler)

@spec put_handler(t(), Skuld.Comp.Types.sig(), Skuld.Comp.Types.handler()) :: t()

Install a handler for an effect signature

with_leave_scope(scope, new_leave_scope)

@spec with_leave_scope(t(), Skuld.Comp.Types.leave_scope()) :: t()

Install a new leave-scope handler

with_transform_suspend(scope, new_transform_suspend)

@spec with_transform_suspend(t(), Skuld.Comp.Types.transform_suspend()) :: t()

Install a new transform-suspend handler