Open turion opened 5 months ago
Another great example would be adding a kind of CRDT constraint on the internal state. Then it is conceivable that we could run two copies of the same program on different machines, constantly synchronising their state.
In https://github.com/turion/essence-of-live-coding/ there is a type that is very similar to
AutomatonT
, but it differs by having theData
constraint on the internal state. This was an arbitrary decision, and any other serialization type with sufficient introspection would be suitable as well, e.g.Generic
, or maybe evenIsAcidic
(see https://github.com/turion/essence-of-live-coding/issues/124). There might also be other constraints that give useful features.The idea is to generalise
StreamT
(and thus all other types) to include one more type level argumentc
:Instantiating
c
atData
would then give the current implementation ofessence-of-live-coding
, allowing to refactor it and reduce the code base. Instantiating it atIsAcidic
gives applications whose state can be persisted usingacid-state
, and so on.The downside is that this changes a lot of type signatures. It might be possible to create a type alias and use this:
But it's unclear how ergonomic this is, since still all functions need to be written in the more general style.
For some functions, the type signature is even more restricted. Whenever state is added, we need to make sure the whole state is an instance of the type class. E.g. the type signature of
feedback
might now be: