Skip to content

Instantly share code, notes, and snippets.

@retronym
Created March 12, 2011 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/867149 to your computer and use it in GitHub Desktop.
Save retronym/867149 to your computer and use it in GitHub Desktop.
Passing a list of types to a Scala annotation
import TList._
class sealedd[TS <: TL[_ <: Singleton]] extends Annotation
object test {
@sealedd[Value.A.type :: Value.B.type :: TNil[_ <: Singleton]]
trait Value
object Value {
object A extends Value
object B extends Value
}
}
// Borrowed from https://github.com/harrah/up/blob/master/TList.scala
sealed trait TList {
type Head <: Value
type Tail <: TL[Value]
type Value
}
sealed trait TCons[H <: T#Value, T <: TList] extends TList {
type Head = H
type Tail = T
type Value = T#Value
}
sealed trait TNil[V] extends TList {
type Head = Nothing
type Tail = Nothing
type Value = V
}
object TList {
type ::[H <: T#Value, T <: TList] = TCons[H, T]
type TL[V] = TList { type Value <: V }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment