Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:50:14+00:00 2026-06-11T11:50:14+00:00

In Programming in Scala page 436, the author gives an example of the compiler

  • 0

In Programming in Scala page 436, the author gives an example of the compiler checking that each type parameter is only used in positions that are classified appropriately.

abstract class Cat[-T, +U] {
  def meow[W^-](volume: T^-, listener: Cat[U^+, T^-]^-) : Cat[Cat[U^+, T^-]^-, U^+]^+
}

How does the example work out? Why do W and the first T get a negative sign? How does the algorithm actually work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:50:15+00:00Added an answer on June 11, 2026 at 11:50 am

    http://www.artima.com/pins1ed/type-parameterization.html

    19.4 in 1st ed.

    “Method value parameter positions are classified to the flipped classification relative to positions outside the method.”

    “Besides method value parameter positions, the current classification is also flipped at the type parameters of methods.”

    Flipped in this case means “flipped from positive”, hence, negative.

    For bonus points, generate a LOLcats that illustrates a physical interpretation of this model.

    Additional Q&A:

    Okay let's look at the 3rd value parameter "listener".
    
    It has a annotation of: Cat[U^+, T^-]^-.
    
    Why does U have +? Why does T have -? Why does the whole thing have a -?
    

    The method param is a contravariant position, hence the outermost (right-most) minus.

    The type params to Cat are [-T, +U], so in this flipped position, [+, -]. (The actual params being applied, [U, T], aren’t relevant.) It checks because the actual params are co- and contra-variant, respectively.

    More questions:

    Could you kindly describe on SO why the return value type has the following annotation
    for the sake of completeness...
    
    Also could you be so kind as to give an example of the following rule?
    
    A classification is sometimes flipped at the type argument position of a type...
    

    This second additional question is the same as your previous first additional question. The two Cat[+,-] illustrate flipping, and the result type Cat[-,+] illustrates not flipping.

    This thread provides further motivation for variance of params (things you pass in) and results (things you get out):

    https://groups.google.com/forum/#!topic/scala-user/ViwLKfvo3ec

    I found the Java discussion and examples (PECS or Naftalin and Wadler) useful background for what Scala provides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Chapter 3 of Programming Scala , the author gives two examples of for
In the book Programming In Scala, chapter 23, the author give an example like:
I don't understand why authors said that Code Listing 9.1 from Programming in Scala
In Programming in Scala, page 239, the first paragraph says: Composition and inheritance are
I'm a newbie to scala. I'm trying an example from the book Programming Scala.
In the book Programming in Scala from Martin Odersky there is a simple example
In Chapter 9 of Programming In Scala, there is an example method like this:
The following example is from the book 'Programming in Scala'. Given a class 'Rational'
According to Programming in Scala one can pass the argument -Xprint:typer to the compiler
From reading parts of the Programming in Scala book, I realize that Scala can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.