Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscores in type bounds on type constructors

Can someone explain why the following doesn't compile? I want that BB[A] is also a List[A]. The method body only enforces this view.

scala> def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]}
<console>:8: error: type mismatch;
 found   : BB[A]
 required: List[A]

       def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]}
                                             ^
like image 774
ziggystar Avatar asked Jun 27 '11 12:06

ziggystar


1 Answers

I think you need to name the _ parameter.

scala> def x[A, BB[X] <: List[X]](p: BB[A]) {p: List[A]}

works.

like image 68
n. 1.8e9-where's-my-share m. Avatar answered Sep 19 '22 09:09

n. 1.8e9-where's-my-share m.