Skip to content

Typos (twice the same) in Tour of Scala : Variances #2773

@QuentinCazelles

Description

@QuentinCazelles

In section "Covariance":

We say that ImmutableBox is covariant in A, and this is indicated by the + before the A.

More formally, that gives us the following relationship: given some class Cov[+T], then if A is a subtype of B, Cov[A] is a subtype of Cov[B]. This allows us to make very useful and intuitive subtyping relationships using generics.

In section "Contravariance":

We say that Serializer is contravariant in A, and this is indicated by the - before the A. A more general serializer is a subtype of a more specific serializer.

More formally, that gives us the reverse relationship: given some class Contra[-T], then if A is a subtype of B, Contra[B] is a subtype of Contra[A].


As stated in "Generic classes":

One convention is to use the letter A as type parameter identifier, though any parameter name may be used.


class Cov[+T] should be class Cov[+A].

class Contra[-T] should be class Contra[-A].


For context:

  • Starting Scala
  • Started Tour from beginning, never met generic defined with T letter
  • In Java, convention is to use letter T instead of A as in Scala 3 (I think this is main reason for this issue.)

Not really sure with this.
I can make a PR when confirmed.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions