Skip to content

Commit 5b0b9e5

Browse files
authored
Merge pull request #982 from SethTisue/tut-fix-in-variance-section-of-tour
fix non-compiling tut code in tour
2 parents e3ae6a6 + 3529b38 commit 5b0b9e5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

_tour/variances.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ Another example that can help one understand variance is `trait Function1[-T, +R
143143
Assume the similar `Cat`, `Dog`, `Animal` inheritance tree used earlier, plus the following:
144144

145145
```tut
146-
class SmallAnimal extends Animal
147-
class Mouse extends SmallAnimal
146+
abstract class SmallAnimal extends Animal
147+
case class Mouse(name: String) extends SmallAnimal
148148
```
149149

150150
Suppose we're working with functions that accept types of animals, and return the types of food they eat. If we would like a `Cat => SmallAnimal` (because cats eat small animals), but are given a `Animal => Mouse` instead, our program will still work. Intuitively an `Animal => Mouse` will still accept a `Cat` as an argument, because a `Cat` is an `Animal`, and it returns a `Mouse`, which is also an `SmallAnimal`. Since we can safely and invisibly substitute the former for the latter, we can say `Animal => Mouse` is a subtype of `Cat => SmallAnimal`.

0 commit comments

Comments
 (0)