I have a bunch of data class types that look the same.
trait FooStore[C] { def create(f: FooId => Foo)(c: C): Foo // update and find methods }
I would like to simplify things and was hoping to use dependent types of methods to get something closer to
sealed trait AR { type Id type Type } sealed trait FooAR extends AR { type Id = FooId type Type = Foo } trait DataStore[C] { def create(ar: AR)(f: ar.Id => ar.Type)(c: C): ar.Type }
but when I try to create an instance of this as shown below
case class InMemory(foos: List[Foo]) object InMemory { lazy val InMemoryDataStore: DataStore[InMemory] = new DataStore[InMemory] { def create(ar: AR)(f: ar.Id => ar.Type)(c: InMemory): ar.Type = sys.error("not implemented") } }
I get the following compilation error
object creation impossible, since method create in trait DataStore of type (ar: AR)(f: ar.Id => ar.Type)(c: InMemory)ar.Type is not defined lazy val InMemoryDataStore: DataStore[InMemory] = new DataStore[InMemory] { ^ one error found
I do not understand, since this method is quite clearly defined in the DataStore instance. What does the error mean and is it possible? If not, is there another way to accomplish the same thing?
purefn
source share