Created
May 15, 2016 20:09
-
-
Save m-alvarez/62f52c230e66de4af8d00e35461e1a46 to your computer and use it in GitHub Desktop.
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 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