Skip to content

Commit

Permalink
unreachable case
Browse files Browse the repository at this point in the history
  • Loading branch information
bblfish committed Jun 24, 2023
1 parent 629e36f commit 97dea61
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scala/RDF.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import scala.util.Try
import scala.reflect.TypeTest


trait RDF:
rdf =>

type R = rdf.type
type Node <: Matchable
type URI <: Node
type BNode <: Node

given rops: ROps[R]
end RDF
Expand All @@ -17,24 +20,31 @@ object RDF:
type URI[R <: RDF] <: Node[R] = R match
case GetURI[u] => u & Node[R]

type BNode[R <: RDF] <: Node[R] = R match
case GetBNode[b] => b & Node[R]

type Subject[R <: RDF] = URI[R] | BNode[R]

private type GetNode[N] = RDF { type Node = N }
private type GetURI[U] = RDF { type URI = U }
private type GetBNode[B] = RDF { type BNode = B }
end RDF

trait ROps[R <: RDF]:
def mkUri(str: String): Try[RDF.URI[R]]
def auth(uri: RDF.URI[R]): Try[String]
given subjToURITT: TypeTest[RDF.Subject[R], RDF.URI[R]]

object TraitTypes:
trait Node:
def value: String

trait Uri extends Node

trait BNode extends Node

def mkUri(u: String): Uri =
new Uri { def value = u }


object TraitRDF extends RDF:
import TraitTypes as tz

Expand All @@ -46,6 +56,12 @@ object TraitRDF extends RDF:
override def auth(uri: RDF.URI[R]): Try[String] =
Try(java.net.URI.create(uri.value).getAuthority())

given subjToURITT: TypeTest[RDF.Subject[R], RDF.URI[R]] with
override def unapply(s: RDF.Subject[R]): Option[s.type & URI] =
s match
case x: (s.type & RDF.URI[R]) => Some(x)
case _ => None

end TraitRDF

class Test[R <: RDF](using rops: ROps[R]):
Expand Down

0 comments on commit 97dea61

Please sign in to comment.