hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/lib/effects.json
{
"name": "hydra.core.lib.effects",
"metadata": {
"description": "Primitives in the hydra.core.lib.effects module.",
"comments": [
"A value of effect<t> describes a deferred, executable computation which, when executed by a host interpreter, produces a value of type t; describing a computation is separate from executing it, and Hydra uses the effect type to keep that boundary explicit.",
"There is no eliminator (cases) for effects: an effect value is opaque, consumable only by further composition within this module or by an executor outside the language.",
"Every primitive in this module is pure: constructing or composing an effect description is a referentially transparent operation on ordinary values, and nothing observable happens until an executor runs the description. Effect descriptions have no identity semantics -- two equal descriptions are interchangeable -- so the usual pure-term transformations are valid over effect-building code. (Purity is independent of implementation strategy: a host may implement these combinators natively rather than from a default implementation.)",
"A host interpreter of effect<t> must honor, in addition to the purity of the combinators above: purity of construction (building or composing a description performs no host interaction; only an executor performing the described computation may interact with the host); order (when a combinator specifies an order between the effects it composes, an executor performs them in exactly that order); exactly-once (each composed effect is performed exactly once per execution, never skipped, never repeated); and deferral (an effect specified to run after another must not be performed, nor its producing function evaluated for effect, until the prior effect has run to completion and its value is available). These obligations are observable -- the effects are real host interactions -- so they are normative, not advisory.",
"effect<t> is total: a leaf effect always completes and yields a value (for hydra.lib.files, an either<FileError, t>); the obligations above govern order, multiplicity, and deferral, not failure short-circuiting."],
"seeAlso": [],
"provisions": []},
"dependencies": [{"module": "hydra.core.model"}, {"module": "hydra.core.packaging"}, {"module": "hydra.core.typing"}],
"definitions": [
{
"primitive": {
"name": "hydra.core.lib.effects.apply",
"metadata": {
"description": "Applicative apply for effects.",
"comments": [
"apply(ef, ex) describes an effectful computation which first interprets ef to produce a function, then interprets ex to produce an argument, and returns the result of applying the function to the argument."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.apply.appliesEffectfulFunctionToEffectfulArgument",
"kind": "requirement",
"statement": "apply interprets the function-producing effect and the argument-producing effect, then applies the resulting function to the resulting argument."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "ef",
"description": "the effect producing the function to apply",
"type": {"effect": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}}},
"isLazy": false},
{
"name": "ex",
"description": "the effect producing the argument",
"type": {"effect": {"variable": "x"}},
"isLazy": false}],
"result": {"type": {"effect": {"variable": "y"}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.bind",
"metadata": {
"description": "Sequence two effectful computations.",
"comments": [
"bind(e, f) describes an effectful computation which first interprets e, then passes its result to f to obtain the next effect.",
"Host interpreters provide the operational meaning; Hydra uses the type effect<t> to keep the effect boundary explicit."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.bind.threadsResultIntoNextEffect",
"kind": "requirement",
"statement": "bind passes the result of the first effect to the given function to obtain the next effect, whose result is the overall result."},
{
"name": "hydra.core.lib.effects.bind.performsEffectsInOrderExactlyOnce",
"kind": "requirement",
"statement": "bind performs the first effect to completion, exactly once, before performing the second effect, also exactly once -- observable via real host side effects (not merely by return value), ruling out a host that reorders, double-runs, skips, or eagerly runs either effect."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{"name": "e", "description": "the effect to interpret first", "type": {"effect": {"variable": "x"}}, "isLazy": false},
{
"name": "f",
"description": "the function producing the next effect from e's result",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"effect": {"variable": "y"}}}},
"isLazy": false}],
"result": {"type": {"effect": {"variable": "y"}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.compose",
"metadata": {
"description": "Kleisli composition for effects.",
"comments": ["compose(f, g, x) describes an effectful computation equivalent to bind(f(x), g)."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.compose.sequencesTwoKleisliArrows",
"kind": "requirement",
"statement": "compose(f, g, x) runs f on x to obtain the first effect, then runs g on that effect's result to obtain the second effect, equivalent to bind(f(x), g)."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}, {"name": "z", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the first effect-returning function",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"effect": {"variable": "y"}}}},
"isLazy": false},
{
"name": "g",
"description": "the second effect-returning function",
"type": {"function": {"domain": {"variable": "y"}, "codomain": {"effect": {"variable": "z"}}}},
"isLazy": false},
{"name": "x", "description": "the input to the composed computation", "type": {"variable": "x"}, "isLazy": false}],
"result": {"type": {"effect": {"variable": "z"}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.foldList",
"metadata": {
"description": "Left-fold over a list with an effect-returning function.",
"comments": [
"foldList(f, acc0, xs) describes an effectful left fold over xs, sequencing applications of f from left to right.",
"Renamed from hydra.lib.effects.foldl."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.effects.foldList.sequencesEffectReturningStepOverList",
"kind": "requirement",
"statement": "foldList sequences an effect-returning step function over the list's elements, threading the accumulator through, and the overall result is the final accumulator."},
{
"name": "hydra.core.lib.effects.foldList.performsElementEffectsLeftToRightExactlyOnce",
"kind": "requirement",
"statement": "foldList performs the element effects left-to-right in list order, each exactly once -- observable via real host side effects, ruling out a host that reorders, double-runs, or skips an element's effect."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the effect-returning combining function",
"type": {
"function": {
"domain": {"variable": "x"},
"codomain": {"function": {"domain": {"variable": "y"}, "codomain": {"effect": {"variable": "x"}}}}}},
"isLazy": false},
{"name": "acc0", "description": "the initial accumulator value", "type": {"variable": "x"}, "isLazy": false},
{"name": "xs", "description": "the list to fold over", "type": {"list": {"variable": "y"}}, "isLazy": false}],
"result": {"type": {"effect": {"variable": "x"}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.map",
"metadata": {
"description": "Map a pure function over the result of an effect.",
"comments": [
"map(f, e) describes an effectful computation which interprets e and applies f to its result.",
"Equivalent to bind(e, \\x -> pure(f x))."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.map.appliesPureFunctionToEffectResult",
"kind": "requirement",
"statement": "map interprets the given effect and applies the pure function to its result; equivalent to bind(e, \\x -> pure(f x))."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the pure function to apply to the effect's result",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}},
"isLazy": false},
{"name": "e", "description": "the effect to interpret", "type": {"effect": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"effect": {"variable": "y"}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.mapList",
"metadata": {
"description": "Map an effect-returning function over a list.",
"comments": [
"mapList(f, xs) describes an effectful computation which applies f to each element of xs from left to right and collects the results."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.mapList.appliesEffectReturningFunctionAndCollectsResults",
"kind": "requirement",
"statement": "mapList applies the effect-returning function to each element and collects the per-element results into a list of the same length, in order."},
{
"name": "hydra.core.lib.effects.mapList.performsElementEffectsLeftToRightExactlyOnce",
"kind": "requirement",
"statement": "mapList performs the element effects left-to-right in list order, each exactly once -- observable via real host side effects, ruling out a host that reorders, double-runs, or skips an element's effect."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the effect-returning function to apply to each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"effect": {"variable": "y"}}}},
"isLazy": false},
{"name": "xs", "description": "the list to map over", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"effect": {"list": {"variable": "y"}}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.mapOptional",
"metadata": {
"description": "Map an effect-returning function over an optional.",
"comments": [
"mapOptional(f, m) describes an effectful computation which returns none when m is none, or applies f to the contained value and wraps the result in given."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.mapOptional.appliesFunctionWhenPresentPassesThroughNoneWhenAbsent",
"kind": "requirement",
"statement": "mapOptional over a present value applies the effect-returning function and wraps the result in given; mapOptional over none yields none, with the function not applied."},
{
"name": "hydra.core.lib.effects.mapOptional.performsExactlyZeroOrOneEffect",
"kind": "requirement",
"statement": "mapOptional over none performs zero effects; mapOptional over a present value performs exactly one effect -- observable via a real host side effect, distinguishing \"the function was never invoked\" from \"the function was invoked and its effect ran\"."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the effect-returning function to apply to the contained value",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"effect": {"variable": "y"}}}},
"isLazy": false},
{"name": "m", "description": "the optional to map over", "type": {"optional": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"effect": {"optional": {"variable": "y"}}}}},
"isPure": false,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.effects.pure",
"metadata": {
"description": "Lift a pure value into an effect.",
"comments": ["pure(x) describes an effectful computation which succeeds with x without requiring host interaction."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17"},
"provisions": [
{
"name": "hydra.core.lib.effects.pure.liftsValueWithoutHostInteraction",
"kind": "requirement",
"statement": "pure(x) succeeds with exactly x, without requiring any host interaction."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "x", "description": "the pure value to lift into an effect", "type": {"variable": "x"}, "isLazy": false}],
"result": {"type": {"effect": {"variable": "x"}}}},
"isPure": false,
"isTotal": true}}]}