For the second part of the question, there are two ways to limit the allowed types.
The first would be to put a bound on the type, which would limit the allowable types, but would not allow the compiler to do meaningful completeness checks as the types could be defined pretty much anywhere or any time.
The second would be to wrap the type in a sealed trait, but then you are essentially creating a case class for each type, so you might as well remove the extra layer of wrapping and simply create DoubleBox
, StringBox
, etc.