Using shapeless to model a Module

36 views
Skip to first unread message

Luis Solano

unread,
Mar 9, 2016, 1:56:37 AM3/9/16
to Typelevel Users & Development List
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

Miles Sabin

unread,
Mar 9, 2016, 6:51:10 AM3/9/16
to Luis Solano, Typelevel Users & Development List
Hi Luis,

The best place to ask questions of this sort is on the shapeless gitter channel,

https://gitter.im/milessabin/shapeless

or possibly on StackOverflow with a shapeless tag ... very few people
read the mailing list these days and there's much more activity
elsewhere.

Cheers,


Miles
> --
> You received this message because you are subscribed to the Google Groups
> "Typelevel Users & Development List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to typelevel+...@googlegroups.com.
> To post to this group, send email to type...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/typelevel/0bbc967a-c3eb-47d7-9f7c-52824e1ae8ad%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
http://milessabin.com/blog
http://twitter.com/milessabin
Reply all
Reply to author
Forward
0 new messages