Hi,
I'm new to Shapeless and let me first tell you that I'm amazed by it.
I'm trying to model a Module, as in a programming language. It has some inputs, some outputs and it may implement some interfaces. Something like this:
case class Input[T]()
case class Output[T]()
case class Module[LI, LO, ???](inputs: Inputs, outputs: Outputs, implements: Interfaces)(implicit ???) {
def inputNamed(symbol: Symbol): Input[T]
}
Inputs would be a labelled HList of Input instances
Outputs the same but with Output instances
Interfaces would be an HList of other Module instances, the parent Modules., basically, a Module can implement other Modules, inheriting all the inputs and outputs.
The type Module is of type LI (Layout of Inputs). The type LI should be inferred from all the inputs and the inputs of all interfaces of the given module. In particular,
it should be an HList of all the inputs in this module + all the inputs in the parent Modules.
The type LO (Layout of Outputs) would be similar. An HList of all the outputs in this module + all the outputs in all the parent Modules
The should be a way of retrieving back and Input or an Output by name, whether that Input or Output was defined in the receiver Module or in a parent Module.
Lastly, a Module m1 and m2 should be replaceable if they both have the same types LI and LO, that is, if they have the same layout.
the usage of it would be something like this:
val m1 = Module(inputs = 'someinput ->> Input[Foo](), 'otherinput ->> Input[Bar]() :: HNil, outputs = 'output ->> Output[String]() :: HNil, interfaces = HNil)
val m2 = Module(inputs = 'extrainput ->> Input[Baz]() :: HNil, outputs = 'extraoutput ->> Output[String]() :: HNil, interfaces = m1 :: HNil)
val m3 = Module(inputs = 'extrainput ->> Input[Baz]() :: HNil, outputs = 'extraoutput ->> Output[String]() :: HNil, interfaces = m1 :: HNil)
var m = m2
var m = m3 // I should be able to swap m2 and m3 cause the have the same layout (they would be wired differently internally)
I have no idea if anything like this is even possible, I'd love some help with this challenge.
Thanks for your time.
- Luis