9 Feb 05:41
Re: Very weird error
Windemuth Andreas <windemut <at> yahoo.com>
2010-02-09 04:41:38 GMT
2010-02-09 04:41:38 GMT
Could it be because MessageWithAction is not covariant in MsgType?
Andreas
From: David Pollak <feeder.of.the.bears <at> gmail.com>
To: Scala list <scala <at> listes.epfl.ch>
Sent: Mon, February 8, 2010 7:44:47 PM
Subject: [sc ala] Very weird error
Folks,
I'm working on some Goat Rodeo code and I'm running into a huge problem with compound types.
I'm got a case class that holds a message and a function to execute on response from the message:
I've got a worker that takes a MessageWithAction as a parameter in one its methods:
And I've got a message:
Now, when I try to send that message:
The compiler complains:
I try to be nice and explicitly tell the compiler that the type parameter for !! is QLong, but I still get:
I'm enclosing a complete example.
So, why doesn't the compiler recognize MooFu as a SimpleMsg with MsgWithResponse[QLong]? How can I help things along?
Thanks,
David
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
To: Scala list <scala <at> listes.epfl.ch>
Sent: Mon, February 8, 2010 7:44:47 PM
Subject: [sc ala] Very weird error
Folks,
I'm working on some Goat Rodeo code and I'm running into a huge problem with compound types.
I'm got a case class that holds a message and a function to execute on response from the message:
MessageWithAction[ActionType <: QBase,
MsgType <: QBase with
MsgWithResponse[ActionType]](msg: MsgType,
timeout: Long,
action: Option[ActionType] => Unit)
MsgType <: QBase with
MsgWithResponse[ActionType]](msg: MsgType,
timeout: Long,
action: Option[ActionType] => Unit)
I've got a worker that takes a MessageWithAction as a parameter in one its methods:
trait Worker[IdType <: WorkerId, MsgType] {
/**
* The unique ID of the Work
*/
def id: IdType
/**
* Send a message to the worker
*/
def !(msg: MsgType): Unit
/**
* Send a message to along with a callback
*/
def !: Unit
}
/**
* The unique ID of the Work
*/
def id: IdType
/**
* Send a message to the worker
*/
def !(msg: MsgType): Unit
/**
* Send a message to along with a callback
*/
def !: Unit
}
And I've got a message:
case class MooFu(str: String) extends SimpleMsg with MsgWithResponse[QLong]
Now, when I try to send that message:
val q = MessageWithAction(MooFu("Hello"), 400L, (a: Option[QLong]) => println(a))
n !! q
n !! q
The compiler complains:
InferThis.scala:73: error: type mismatch;
found : MessageWithAction[QLong,MooFu]
required: MessageWithAction[?,SimpleMsg with MsgWithResponse[?]]
n !! q
^
found : MessageWithAction[QLong,MooFu]
required: MessageWithAction[?,SimpleMsg with MsgWithResponse[?]]
n !! q
^
I try to be nice and explicitly tell the compiler that the type parameter for !! is QLong, but I still get:
InferThis.scala:76: error: type mismatch;
found : MessageWithAction[QLong,MooFu]
required: MessageWithAction[QLong,SimpleMsg with MsgWithResponse[QLong]]
n.!
found : MessageWithAction[QLong,MooFu]
required: MessageWithAction[QLong,SimpleMsg with MsgWithResponse[QLong]]
n.!
I'm enclosing a complete example.
So, why doesn't the compiler recognize MooFu as a SimpleMsg with MsgWithResponse[QLong]? How can I help things along?
Thanks,
David
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
RSS Feed