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?
From its documentation one might think that
unsafeBuildDynamicsimply puts an Event and Behavior together into a Dynamic without any further effects. However, in the Spider implementation it actually does aholdon some starting value sampled from the input Behavior and the updates of the input Event.This in effect makes
unsafeBuildDynamica 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
PullMtype:sampleturns Behaviors intoPullMvalues, which can be combined in arbitrary ways without any caching, andpullturns aPullMvalue 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
PullMandpull, 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, andmapBehaviorCheap?