From 017f106c4d2d08b981f9b48c0982f70b01635582 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 15 Aug 2017 11:50:50 +0300 Subject: [PATCH 1/2] tour/lower-type-boudns: swallows aren't mammals --- _tour/lower-type-bounds.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/_tour/lower-type-bounds.md b/_tour/lower-type-bounds.md index 863f107a50..b81c0829ba 100644 --- a/_tour/lower-type-bounds.md +++ b/_tour/lower-type-bounds.md @@ -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. From c48688ca4e5f1e707e5378bb67d9105e0968ad96 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 15 Aug 2017 11:53:10 +0300 Subject: [PATCH 2/2] tour/lower-type-boudns: Return type annotation on Node.prepend Otherwise, prepend has return type Unit, which is not at all what we want here --- _tour/lower-type-bounds.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tour/lower-type-bounds.md b/_tour/lower-type-bounds.md index b81c0829ba..ee1ddee169 100644 --- a/_tour/lower-type-bounds.md +++ b/_tour/lower-type-bounds.md @@ -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] {