开发者

Scala 2.8 weird type error

Types:

def radioGroup[T](values: Array[T], textProvider: T => String)(setups:(RadioGroup[T] => Unit)*)(parent: Composite): RadioGroup[T]
def label(setups:(Label => Unit)*)(parent:Composite): Label

def contains(setups : (Composite => Unit)*) : Composite // "Pimp my library" on Composite

This works:

new Composite(parent, SWT.NONE).contains(
  label() // should hav开发者_StackOverflowe type Composite => Label
)

This doesn't:

new Composite(parent, SWT.NONE).contains(
  radioGroup(Array(1,2), (_:Int).toString)() 
   // should have type Composite => RadioGroup[Int]
)

with the following error:

polymorphic expression cannot be instantiated to expected type;
found   : => (org.eclipse.swt.widgets.Composite) => main.scala.RadioGroup[Int]
required: (org.eclipse.swt.widgets.Composite) => Unit

I can annotate the return type of radioGroup to be Unit, but I don't understand 1) how the cases of radioGroup and label can be different; 2) why is there an extra arrow at the beginning of the "found" type in the error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜