I am trying to learn Shapeless (using version 2.10.2). I have created a very simple extensible record:
val rec1 = ("foo" ->> 42) :: HNil
According to the REPL, this has type
shapeless.::[Int with shapeless.record.KeyTag[String("foo"),Int],shapeless.HNil]
I am trying to define a simple function:
def fun(x: ::[Int with KeyTag[String("foo"), Int], HNil]) = x("foo")
but it does not even compile. I cannot use a String("foo") in the type declaration, and get an error.
I have two questions:
- How can I specify the type of the extensible record in my code?
- When working with records with more fields, the length and complexity of the type declaration will be unmanageable. Is there a way to create an alias for the type, given a particular instance of a record, or some other workaround?
EDIT
I have found that:
val rec1 = ("foo" ->> 42) :: HNil
val rec2 = ("foo" ->> 43) :: HNil
var x = rec1
x = rec2
works well. I conclude rec1, rec2, and x are of the same type. I just don't know how to express that type in code!