Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save m-alvarez/62f52c230e66de4af8d00e35461e1a46 to your computer and use it in GitHub Desktop.
Save m-alvarez/62f52c230e66de4af8d00e35461e1a46 to your computer and use it in GitHub Desktop.
package starfighter.types
sealed abstract class TList
sealed class TNil extends TList
sealed class TCons[A, B <: TList] extends TList
object TList {
type L[A] = TCons[A, TNil]
type ::[A, B <: TList] = TCons[A, B]
}
sealed class OneOfC[A, L <: TList]
sealed class OneOf[L <: TList] { type T[A] = OneOfC[A, L] }
object OneOf {
implicit def head[A, C <: TList]: OneOfC[A, TCons[A, C]] =
new OneOfC[A, TCons[A, C]]
implicit def tail[A, B, C <: TList](implicit foo : OneOfC[A, C]) : OneOfC[A, TCons[B, C]] =
new OneOfC[A, TCons[B, C]]
}
object Test {
import OneOf._
import TList._
def example[T: OneOf[ Int :: L[String] ]#T](x:T) = {
}
def foo() = { example("hello") } // This works
def bar() = { example(5) } // This works
def baz() = { example(new Array[Int](100)) } // This fails
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment