Replacing projection types #12527
Replies: 2 comments 9 replies
-
Here is a simple interaction problem I have come across regarding inherited projection types. Banana RDF projection types are defined in the RDF trait which starts like this: trait RDF {
// types related to the RDF datamodel
type Graph
type Triple
type Node
type URI <: Node
type BNode <: Node
type Literal <: Node This trait is implemented for a number of RDF frameworks such as the Apache Jena project (started at HP in the early 2000s). The Jena trait for example just specifies how those types should be translated for the Jena class hierarchy. It looks like implicit transformations which work in Java 2.13 don't work that well anymore when using the library in Scala 3.0. We use this for example for our DSL, to allow people to write RDF in a Scala friendly way: val g: PointedGraph[Rdf] = (
bnode("betehess")
-- foaf.name ->- "Alexandre".lang("fr")
-- foaf.knows ->- (
URI("http://bblfish.net/#hjs")
-- foaf.name ->- "Henry Story"
-- foaf.currentProject ->- URI("http://webid.info/")
)
) This requires Scala to convert a URI into a implicit def ToNodeToPG[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], to: ToNode[Rdf, T]): ToPG[Rdf,T] = new ToPG[Rdf, T] {
def toPG(t: T): PointedGraph[Rdf] = PointedGraph(to.toNode(t))
} That seems to work fine on Scala 2.13. But for Scala 3 I seem to need to add: implicit def URIToNode: ToNode[Rdf,Rdf#URI] = new ToNode[Rdf, Rdf#URI] {
def toNode(t: Rdf#URI): Rdf#Node = t
} Is that a bug in Scala3, do I need to write these implicit transformations out explicitly for the inheritance hierarchy, or is there a better way to get this done? |
Beta Was this translation helpful? Give feedback.
-
It looks like Match Types are the answer to my problem. See #13416 and test code. |
Beta Was this translation helpful? Give feedback.
-
Projection types were removed from Dotty. Some libraries like banana-rdf relied on this very heavily to make elegant user libraries.
It looks like some subset of it may not be problematic, as per issue 14: Make type projections safe instead of dropping them.
So we are now in a grey zone where it is not clear whether a safe subset is going to be brought back, or if there is a better way to get the same effect. So I think we should really have this as a whole discussion topic in itself. Questions to look at:
Beta Was this translation helpful? Give feedback.
All reactions