KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Okay, fair warning: this is a follow-up to my ridiculous question from last week. Although I think this question isn't as ridiculous. Anyway, here goes: Previous ridiculous question: Assume I have some base trait T with subclasses A , B and C , I can declare a collection Seq[T] for example, that can contain values of type A , B and C . Making the subtyping more explicit, let's use the Seq[_ <: T] type bound syntax. Now instead assume I have a typeclass TC[_] with members A , B and C (where "member" means the compiler can find some TC[A] , etc. in implicit scope). Similar to above, I want to declare a collection of type Seq[_ : TC] , using context bound syntax. This isn't legal Scala, and attempting to emulate may make you feel like a bad person . Remember that context bound syntax (when used correctly!) desugars into an implicit parameter list for the class or method being defined, which doesn't make any sense here. New premise: So let's assume that typeclass instances (i.e. implicit values) are out of the question, and instead we need to use implicit conversions in this case. I have some type V (the "v" is supposed to stand for "view," fwiw), and implicit conversions in scope A => V , B => V and C => V . Now I can populate a Seq[V] , despite A , B and C being otherwise unrelated. But what if I want a collection of things that are implicitly convertible both to views V1 and V2 ? I can't say Seq[V1 with V2
Tags (comma-separated)
Save Edits
Cancel