9 Feb 17:28
Re: Very weird error
David Pollak <feeder.of.the.bears <at> gmail.com>
2010-02-09 16:28:33 GMT
2010-02-09 16:28:33 GMT
On Mon, Feb 8, 2010 at 8:41 PM, Windemuth Andreas <windemut <at> yahoo.com> wrote:
Yep... PaulP showed me the errors of my ways at the Scala BASE meeting last night. Thanks all!
Could it be because MessageWithAction is not covariant in MsgType?
Yep... PaulP showed me the errors of my ways at the Scala BASE meeting last night. Thanks all!
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: [scala] 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)
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
}
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
The compiler complains:InferThis.scala:73: error: type mismatch;
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.!
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
--
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