scala - Type parameter does not extend given type -


i define generic such type parameter not extend given type.

for example,

trait mytrait[t <: throwable] {   // .... } 

would define trait type parameter extends throwable. want (not real scala code):

trait mytrait[t not(<:) throwable] {   // .... } 

where type type parameter not extend throwable. there way construct such notion in scala?

you can such thing using implicits. here's trick miles sabin on scala-language:

// encoding "a not subtype of b" trait <:!<[a, b]  // uses ambiguity rule out cases we're trying exclude implicit def nsub[a, b] : <:!< b = null implicit def nsubambig1[a, b >: a] : <:!< b = null implicit def nsubambig2[a, b >: a] : <:!< b = null  // type alias context bound type not[t] = {  type lambda[u] = u <:!< t }  // foo not accept t of type unit def foo[t : not[unit]#lambda](t : t) = t 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -