Type parameter a family?

24 views
Skip to first unread message

Siddhartha Gadgil

unread,
Oct 13, 2015, 4:38:54 AM10/13/15
to scala-user
I have a trait with a type parameter and a couple of implementations, say

trait FD[A]

case class FDS[A](...) extends FD[A]

case class FDV[A](...) extends FD[A].

I want a class with a type parameter where I choose a specific implementation, but will use various parameters A. If there were no parameter A, I would write

class Dyn[MyFD <: FD](...)

My question: Is there any way to achieve this with a family of types as above?

Thanks,
Siddhartha

Daniel Armak

unread,
Oct 13, 2015, 7:11:12 AM10/13/15
to Siddhartha Gadgil, scala-user

I’m not sure what you want to accomplish. One option is to write class Dyn[A, MyFD <: FD[A]](...). Then you can use the concrete type of A inside Dyn. If you want to constrain A too, you can write class Dyn[A <: A1, MyFD <: FD[A]](...).


Daniel Armak

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siddhartha Gadgil

unread,
Oct 13, 2015, 7:33:22 AM10/13/15
to Daniel Armak, scala-user

I actually have several types A, so I cannot use that. The one option I thought of was to use a trait with
type MyFD[A] <: FD[A]

The underlying reason is to make my implementation of FD a value class, and avoid creating it, so methods in the class Dyn should have types the specific implementation and not FD[A]. Presently I have FD[A], and that code is logically correct.

Thanks
Siddhartha

Reply all
Reply to author
Forward
0 new messages