Skip to content

unsafeBuildDynamic secretly is ~cacheBehavior, can we be more explicit about all ways to cache Behaviors? #532

Description

@parenthetical

From its documentation one might think that unsafeBuildDynamic simply puts an Event and Behavior together into a Dynamic without any further effects. However, in the Spider implementation it actually does a hold on some starting value sampled from the input Behavior and the updates of the input Event.

This in effect makes unsafeBuildDynamic a function that caches a Behavior's value in-between update occurrences.

There is another way Behavior values are cached, but only for the current moment (frame). This is achieved via the PullM type: sample turns Behaviors into PullM values, which can be combined in arbitrary ways without any caching, and pull turns a PullM value back into a Behavior.
Such a Behavior's value is computed only on-demand, but its computed value is retained for the current moment/frame.

Because the only way to construct Behaviors goes through PullM and pull, it's IIRC not possible to "map cheaply" over behaviors like we can do with events.

Can we create a scheme where we have functions like cacheBehaviorNow, cacheDynamic, and mapBehaviorCheap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions