Last active
November 7, 2017 05:30
-
-
Save tarunon/16c2416f8d164ef8dbefbb2934108f87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal {} | |
class Cat: Animal {} | |
// Rule A | |
// Cat is subtype of Animal | |
do { | |
let cat: Cat = Cat() | |
let animal: Animal = cat | |
} | |
// Rule B | |
// Int is subtype of Int? | |
do { | |
let int: Int = 0 | |
let intOptional: Int? = int // Int?.some(0) | |
} | |
// Rule C | |
// Optional has covariance | |
do { | |
let catOptional: Cat? = Cat?.none | |
let animalOptional: Animal? = catOptional // Animal?.none | |
} | |
// Question | |
// What happen replace `Cat : Animal` to `Int : Int?` | |
do { | |
let intOptional: Int? = Int?.none | |
let intOptionalOptional: Int?? = intOptional // Rule B: Int??.some(.none), Rule C: Int??.none | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment