0

Is it possible to create somehow a context bound for a nested type? Something like this:

def f[T : U[List]](a: T)

Ofc, this is not Scala syntax, but illustrates what I want to achieve, that is, get a bound on an implicit U[List[T]]. Is this possible?

Thanks.

ale64bit
  • 6,232
  • 3
  • 24
  • 44

1 Answers1

3

You could do it with type alias:

type UList[X] = U[List[X]]
def f[T : UList](a: T)

or

def f[T:({type UL[X] = U[List[X]]})#UL](a: T)
Odomontois
  • 15,918
  • 2
  • 36
  • 71
  • Well, I was expecting something without the alias, but not the abomination of the second solution :) I will wait a bit and if there's nothing better I will accept your answer. Thanks! – ale64bit May 22 '15 at 10:24
  • @kaktusito I am very unsatisfied with current synthax for type curring in scala too. – Odomontois May 22 '15 at 10:32
  • Seems like there are some old questions on the topic (as this one http://stackoverflow.com/questions/6247817/is-it-possible-to-curry-higher-kinded-types-in-scala) but then there wasn't attention to it anymore. – ale64bit May 22 '15 at 10:39
  • 1
    If you don't like the syntax for type currying (and who does?) here is the kind projector compiler plugin that allows for a more natural one. – Aldo Stracquadanio May 22 '15 at 10:40