title: Scala trait subclass constraint
body: <p>I have a set of message base on a "Message" trait:</p>
  
  <pre><code>trait Message{
    id: Int
  }
  
  case class AckMsg(id: Int) extends Message
  case class NackMsg(id: Int) extends Message
  </code></pre>
  
  <p>And having some function to take them as parameters:</p>
  
  <pre><code>def replyAck(ack: AckMsg) = { ... }
  
  def replyNack(nack: NackMsg) = { ... }
  </code></pre>
  
  <p>When I am defining some higher level function to leverage the use of those function, I encountered:</p>
  
  <pre><code>def replyingMsg(fun: Message =&gt; Unit): Unit = { ... } 
  
  replyingMsg(replyAck(AckMsg(id)))   //compiling error here!
  </code></pre>
  
  <p>The compiler doesn't like the fact that I have (Message => Unit) but passing (AckMsg => Unit)</p>
  
  <p>So, how can I in replyingMsg, defining something like:</p>
  
  <pre><code>def replyingMsg(fun: M &lt;: Message =&gt; Unit) //imagery code!!!
  </code></pre>
  
  <p>The above code is in error: </p>
  
  <ol>
  <li>For some reason once involve &lt;: Message cannot be a trait, need to be a class</li>
  <li>&lt;: doesn't seems to describing the situation correctly</li>
  </ol>
  
  <p>How can I tell the compiler that I am passing something a subclass of a trait?
  Please someone shed some light on the complicated type system.</p>