Conal Elliott talks about Streams and Comonads here: http://conal.net/blog/posts/sequences-streams-and-segments
However, he doesn't mention Behavior directly. So.. is Behavior a Comonad, and if so - what does that mean practically?
For starters - I suppose Behavior can provide the extend
and extract
functions. The only way I see that working is if it samples the value at a specific moment in time.
Is that what Comonad would mean for Behavior? That it allows one to "fork and freeze" a Behavior?
In other words - if we have a Behavior that has these values over time: A,B,C,D,...
we could extend
it at the time where it's B
, and get a new Behavior which contains B
indefinitely (which is useful - since we could then lift
or map
it etc.)
Behavior a
is isomorphic to (Time -> a)
. The definitions Conal gives in the section of that post "Adding continuity" match those in the comonad package.
It is not obvious to me how to make time a Monoid. Several Monoid instances are possible, but are any useful? Conal's post on future values suggests that the Max
is a useful Monoid for working with time.
This works out that extract @Behavior
gives the value at the earliest possible time, and duplicate @Behavior
gives the value at the later of the two times. I can see both of those being useful. Perhaps there are other useful Monoids also?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With