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
Union type quiz | |
=============== | |
Should there be predefined implicit widening conversions between numbers? | |
( ) Yes, even if they are lossy | |
( ) Yes, but only non-lossy ones | |
( ) No | |
( ) Other: ______________________________ | |
What should be the inferred type of the expression | |
List(1, 1.0)? | |
( ) List[Double] | |
( ) List[AnyVal] | |
( ) List[Int|Double] | |
( ) Other: ______________________________ | |
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: ______________________________ | |
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: ______________________________ | |
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: __________________________________________________ | |
What should be the inferred type of | |
if (true) Some(1) else None? | |
( ) Option[Int] | |
( ) Some[Int]|None | |
( ) Other: ______________________________ | |
What should be the inferred type of | |
if (true) Nil else List(1).asInstanceOf[::[Int]]? | |
( ) List[Int] | |
( ) Nil|::[Int] | |
( ) Other: ______________________________ | |
When, if ever, should a nominal type be prefered to a more precise union type? | |
( ) Always | |
( ) Never | |
( ) Only if the element types enumerate all subclasses/subobjects of a sealed supertype | |
( ) Other: ______________________________ | |
When, if ever, should a more precise structural type be prefered to a union type? | |
( ) Always | |
( ) Never | |
( ) Only if the structural type is specified explicitly | |
( ) Other: ______________________________ | |
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 | |
Will your choice from above break existing, valid code? | |
( ) Yes | |
( ) Yes, but it doesn't matter because: ______________________________ | |
( ) No, because: ______________________________ | |
( ) Maybe? | |
How will inference interact with structural types? | |
__________________________________________________ | |
__________________________________________________ | |
Please give your typing approach an intuitive name: | |
__________________________________________________ | |
Please describe the guiding principle of your typing approach in one sentence: | |
________________________________________________________________________________ | |
________________________________________________________________________________ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment