Created
August 24, 2020 15:44
-
-
Save bblfish/2309886707c9a0b28b01162ee817f672 to your computer and use it in GitHub Desktop.
Trying to get the types in dotty to line up.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.w3.banana | |
import org.w3.banana._ | |
trait RDFOps[Rdf <: RDF & Singleton](using val Rdf: RDF) { | |
def emptyGraph: Rdf.Graph | |
} | |
trait PointedGraph[Rdf <: RDF & Singleton](using val ops: RDFOps[Rdf]) { | |
def pointer: ops.Rdf.Node | |
def graph: ops.Rdf.Graph | |
} | |
object PointedGraph { | |
def apply[Rdf <: RDF & Singleton](using ops: RDFOps[Rdf])( | |
node: ops.Rdf.Node, | |
inGraph: ops.Rdf.Graph | |
): PointedGraph[ops.Rdf.type] = | |
new PointedGraph[ops.Rdf.type](){ | |
val pointer = node | |
val graph = inGraph | |
} | |
def apply[Rdf <: RDF & Singleton](using ops: RDFOps[Rdf])(node: ops.Rdf.Node): PointedGraph[ops.Rdf.type] = | |
this.apply[ops.Rdf.type]()(node, ops.emptyGraph) | |
def unapply[Rdf <: RDF & Singleton](using ops: RDFOps[Rdf])( | |
pg: PointedGraph[ops.Rdf.type] | |
): (pg.ops.Rdf.Node, pg.ops.Rdf.Graph) = (pg.pointer, pg.graph) | |
} |
Ok this compiles:
package org.w3.banana
import org.w3.banana._
trait RDFOps[T <: RDF & Singleton](using val rdf: T) {
def emptyGraph: rdf.Graph
}
trait PointedGraph[T <: RDF & Singleton](using val rdf: T) {
def pointer: rdf.Node
def graph: rdf.Graph
}
object PointedGraph {
def apply[T <: RDF & Singleton](using rdf:T)(
node: rdf.Node,
inGraph: rdf.Graph
): PointedGraph[rdf.type] =
new PointedGraph[rdf.type](){
val pointer = node
val graph = inGraph
}
def apply[T <: RDF & Singleton](using rdf: T) (
node: rdf.Node
)(using ops: RDFOps[rdf.type]): PointedGraph[rdf.type] =
new PointedGraph[rdf.type]() {
val pointer = node
val graph = ops.emptyGraph
}
def unapply[T <: RDF & Singleton](using rdf: T)(
pg: PointedGraph[rdf.type]
)(using ops: RDFOps[T]): (rdf.Node, rdf.Graph) = (pg.pointer, pg.graph)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am having a lot of trouble gettint the types to match up here. These are the error messages
The RDF trait is the following