Skip to content

fixes for tour/Lower type bounds #865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions _tour/lower-type-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To fix this, we need to flip the variance of the type of the parameter `elem` in

```tut
trait Node[+B] {
def prepend[U >: B](elem: U)
def prepend[U >: B](elem: U): Node[B]
}

case class ListNode[+B](h: B, t: Node[B]) extends Node[B] {
Expand All @@ -58,13 +58,13 @@ case class Nil[+B]() extends Node[B] {

Now we can do the following:
```tut
trait Mammal
case class AfricanSwallow() extends Mammal
case class EuropeanSwallow() extends Mammal
trait Bird
case class AfricanSwallow() extends Bird
case class EuropeanSwallow() extends Bird


val africanSwallowList= ListNode[AfricanSwallow](AfricanSwallow(), Nil())
val mammalList: Node[Mammal] = africanSwallowList
mammalList.prepend(new EuropeanSwallow)
val birdList: Node[Bird] = africanSwallowList
birdList.prepend(new EuropeanSwallow)
```
The `Node[Mammal]` can be assigned the `africanSwallowList` but then accept `EuropeanSwallow`s.
The `Node[Bird]` can be assigned the `africanSwallowList` but then accept `EuropeanSwallow`s.