Last active
December 18, 2015 11:38
-
-
Save soc/5776653 to your computer and use it in GitHub Desktop.
The Union Type Quiz
This file contains hidden or 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
The Union Type Quiz | |
=================== | |
0. Please give your typing approach an intuitive name: | |
__________________________________________________ | |
1. Please describe the guiding principle of your typing approach in one sentence: | |
________________________________________________________________________________ | |
________________________________________________________________________________ | |
2. Should there be predefined implicit widening conversions between numbers? | |
( ) Yes, even if they are lossy | |
( ) Yes, but only non-lossy ones | |
( ) No | |
( ) Other: ______________________________ | |
3. What should be the inferred type of the expression | |
List(1, 1.0)? | |
( ) List[Double] | |
( ) List[AnyVal] | |
( ) List[Int|Double] | |
( ) Other: ______________________________ | |
4. What should be the inferred type of the expression | |
List(1: java.lang.Integer, 1.0: java.lang.Double)? | |
( ) List[Number with Comparable[_ >: Double with Integer <: Number with Comparable[_ >: Double with Integer <: Number ...]]] | |
( ) List[java.lang.Integer|java.lang.Double] | |
( ) Other: ______________________________ | |
5. Do you prefer a union type A|B to Either[A, B]? | |
( ) Always | |
( ) Never | |
( ) Sometimes: ______________________________ | |
( ) Other: ______________________________ | |
Why? | |
__________________________________________________ | |
__________________________________________________ | |
6. Do prefer a nullable type T? to e. g. Option[T]? | |
( ) Always | |
( ) Never | |
( ) Sometimes: ______________________________ | |
( ) Other: ______________________________ | |
Why? | |
__________________________________________________ | |
__________________________________________________ | |
7. Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]: | |
________________________________________________________________________________ | |
________________________________________________________________________________ | |
________________________________________________________________________________ | |
8. Given the following declarations ... | |
trait T | |
object A extends T | |
object B extends T | |
... what should be the inferred type of | |
if (true) A else B | |
( ) T | |
( ) A|B | |
( ) Other: ______________________________ | |
9. Does your answer change if | |
- trait T is sealed? | |
( ) Yes, because: __________________________________________________ | |
( ) No, because: __________________________________________________ | |
- A and/or B are classes? | |
( ) Yes, because: __________________________________________________ | |
( ) No, because: __________________________________________________ | |
- A/B/T are type constructors? | |
( ) Yes, because: __________________________________________________ | |
( ) No, because: __________________________________________________ | |
10. What should be the inferred type of | |
if (true) Some(1) else None? | |
( ) Option[Int] | |
( ) Some[Int]|None | |
( ) Other: ______________________________ | |
11. What should be the inferred type of | |
if (true) Nil else List(1).asInstanceOf[::[Int]]? | |
( ) List[Int] | |
( ) Nil|::[Int] | |
( ) Other: ______________________________ | |
12. When should a nominal type be preferred to a more precise union type? | |
( ) Always | |
( ) Never | |
( ) Only if the element types enumerate all subclasses/subobjects of a sealed supertype | |
( ) Other: ______________________________ | |
13. When should a more precise structural type be preferred to a union type? | |
( ) Always | |
( ) Never | |
( ) Only if the structural type is specified explicitly | |
( ) Other: ______________________________ | |
14. Given the following declarations ... | |
trait T { def foo: Int } | |
class A extends T { def foo: Int = ???; def bar: Int = ??? } | |
class B extends T { def foo: Int = ???; def bar: Int = ???; def bippy: Int = ??? } | |
... which members are allowed to be called on an instance aOrB of type A|B? | |
[ ] aOrB.toString | |
[ ] aOrB.foo | |
[ ] aOrB.bar | |
[ ] aOrB.bippy | |
15. How will inference of union types interact with structural types? | |
__________________________________________________ | |
__________________________________________________ | |
16. Given the following definitions ... | |
val x: AnyRef { def foo: Int } = null | |
val y: AnyRef { def foo: Int } = null | |
... should it be allowed to call xOrY.foo? | |
( ) Yes | |
( ) No | |
( ) Other: ______________________________ | |
17. Given the following definitions ... | |
val x = new AnyRef { def foo: Int = 23} | |
val y = new AnyRef { def foo: Int = 42} | |
... should it be allowed to call xOrY.foo? | |
( ) Yes | |
( ) No | |
( ) Other: ______________________________ | |
18. Will your design break existing, valid code? | |
( ) Yes | |
( ) Yes, but it doesn't matter because: ______________________________ | |
( ) No, because: ______________________________ | |
( ) Maybe? | |
19. Describe how null will work with union types: | |
________________________________________________________________________________ | |
________________________________________________________________________________ | |
20. Will your design make a difference whether a type has been inferred and has been specified explicitly? | |
________________________________________________________________________________ | |
________________________________________________________________________________ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment