As discussed during today's Tuura meeting, we need a way to compose two concepts by matching some of their interface signals. As a simple example, consider connecting two buffers together in sequence:
data S1 = A | B | C | ...
b1 :: CircuitConcept S1
b1 = buffer A B
data S2 = X | Y | ...
b2 :: CircuitConcept S2
b2 = buffer X Y
-- This won't compile due to type mismatch
composition = b1 <> b2
How do we tell that we want to connect b1's output B to b2's input X?
A good solution seems to rely on wrappers:
wrap :: (a -> b) -> CircuitConcept a -> CircuitConcept b
wrap = ...
map21 :: S2 -> S1
map21 X = B
map21 Y = C
composition :: CircuitConcept S1
composition = b1 <> wrap map21 b2
An alert reader will spot that wrap is just an fmap! Indeed, all we need to do is to write a Functor instance for CircuitConcept, and then we will be able to wrap simply by fmap map21 b2 or map21 <$> b2 using a fancy standard operator.
I'll give this a try.
As discussed during today's Tuura meeting, we need a way to compose two concepts by matching some of their interface signals. As a simple example, consider connecting two buffers together in sequence:
How do we tell that we want to connect
b1's outputBtob2's inputX?A good solution seems to rely on wrappers:
An alert reader will spot that
wrapis just anfmap! Indeed, all we need to do is to write aFunctorinstance forCircuitConcept, and then we will be able to wrap simply byfmap map21 b2ormap21 <$> b2using a fancy standard operator.I'll give this a try.