Skip to content

Instantly share code, notes, and snippets.

@soc
Last active December 18, 2015 11:38

Revisions

  1. soc revised this gist Jun 14, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -173,6 +173,7 @@ The Union Type Quiz
    ( ) No, because: ______________________________
    ( ) Maybe?


    19. Describe how null will work with union types:
    ________________________________________________________________________________
    ________________________________________________________________________________
  2. soc revised this gist Jun 14, 2013. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -166,14 +166,18 @@ The Union Type Quiz
    ( ) Other: ______________________________


    18. Will your choice from above break existing, valid code?
    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:
    ________________________________________________________________________________
    ________________________________________________________________________________


    19. Will your design make a difference whether a type has been inferred and has been specified explicitly?
    20. Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________
  3. soc revised this gist Jun 14, 2013. 1 changed file with 27 additions and 28 deletions.
    55 changes: 27 additions & 28 deletions The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,24 @@
    The Union Type Quiz
    ===================

    1. Should there be predefined implicit widening conversions between numbers?
    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: ______________________________


    2. What should be the inferred type of the expression
    3. What should be the inferred type of the expression
    List(1, 1.0)?

    ( ) List[Double]
    @@ -18,15 +27,15 @@ The Union Type Quiz
    ( ) Other: ______________________________


    3. What should be the inferred type of the expression
    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: ______________________________


    4. Do you prefer a union type A|B to Either[A, B]?
    5. Do you prefer a union type A|B to Either[A, B]?

    ( ) Always
    ( ) Never
    @@ -38,7 +47,7 @@ The Union Type Quiz
    __________________________________________________


    5. Do prefer a nullable type T? to e. g. Option[T]?
    6. Do prefer a nullable type T? to e. g. Option[T]?

    ( ) Always
    ( ) Never
    @@ -50,13 +59,13 @@ The Union Type Quiz
    __________________________________________________


    6. Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]:
    7. Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]:
    ________________________________________________________________________________
    ________________________________________________________________________________
    ________________________________________________________________________________


    7. Given the following declarations ...
    8. Given the following declarations ...

    trait T
    object A extends T
    @@ -70,7 +79,7 @@ The Union Type Quiz
    ( ) Other: ______________________________


    8. Does your answer change if
    9. Does your answer change if
    - trait T is sealed?
    ( ) Yes, because: __________________________________________________
    ( ) No, because: __________________________________________________
    @@ -82,39 +91,39 @@ The Union Type Quiz
    ( ) No, because: __________________________________________________


    9. What should be the inferred type of
    10. What should be the inferred type of
    if (true) Some(1) else None?

    ( ) Option[Int]
    ( ) Some[Int]|None
    ( ) Other: ______________________________


    10. What should be the inferred type of
    11. What should be the inferred type of
    if (true) Nil else List(1).asInstanceOf[::[Int]]?

    ( ) List[Int]
    ( ) Nil|::[Int]
    ( ) Other: ______________________________


    11. When should a nominal type be preferred to a more precise union type?
    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: ______________________________


    12. When should a more precise structural type be preferred to a union type?
    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: ______________________________


    13. Given the following declarations ...
    14. Given the following declarations ...

    trait T { def foo: Int }
    class A extends T { def foo: Int = ???; def bar: Int = ??? }
    @@ -128,12 +137,12 @@ The Union Type Quiz
    [ ] aOrB.bippy


    14. How will inference of union types interact with structural types?
    15. How will inference of union types interact with structural types?
    __________________________________________________
    __________________________________________________


    15. Given the following definitions ...
    16. Given the following definitions ...

    val x: AnyRef { def foo: Int } = null
    val y: AnyRef { def foo: Int } = null
    @@ -145,7 +154,7 @@ The Union Type Quiz
    ( ) Other: ______________________________


    16. Given the following definitions ...
    17. Given the following definitions ...

    val x = new AnyRef { def foo: Int = 23}
    val y = new AnyRef { def foo: Int = 42}
    @@ -157,24 +166,14 @@ The Union Type Quiz
    ( ) Other: ______________________________


    17. Will your choice from above break existing, valid code?
    18. Will your choice from above break existing, valid code?

    ( ) Yes
    ( ) Yes, but it doesn't matter because: ______________________________
    ( ) No, because: ______________________________
    ( ) Maybe?


    18. Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________


    19. Please give your typing approach an intuitive name:
    __________________________________________________


    20. Please describe the guiding principle of your typing approach in one sentence:
    19. Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________

  4. soc revised this gist Jun 14, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@ The Union Type Quiz

    ( ) Option[Int]
    ( ) Some[Int]|None
    ( ) Other: ______________________________
    ( ) Other: ______________________________


    10. What should be the inferred type of
  5. soc revised this gist Jun 14, 2013. 1 changed file with 113 additions and 113 deletions.
    226 changes: 113 additions & 113 deletions The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -1,180 +1,180 @@
    The Union Type Quiz
    ===================

    Should there be predefined implicit widening conversions between numbers?
    1. Should there be predefined implicit widening conversions between numbers?

    ( ) Yes, even if they are lossy
    ( ) Yes, but only non-lossy ones
    ( ) No
    ( ) Other: ______________________________
    ( ) 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)?
    2. What should be the inferred type of the expression
    List(1, 1.0)?

    ( ) List[Double]
    ( ) List[AnyVal]
    ( ) List[Int|Double]
    ( ) Other: ______________________________
    ( ) 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)?
    3. 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: ______________________________
    ( ) List[Number with Comparable[_ >: Double with Integer <: Number with Comparable[_ >: Double with Integer <: Number ...]]]
    ( ) List[java.lang.Integer|java.lang.Double]
    ( ) Other: ______________________________


    Do you prefer a union type A|B to Either[A, B]?
    4. Do you prefer a union type A|B to Either[A, B]?

    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________
    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________

    Why?
    __________________________________________________
    __________________________________________________
    Why?
    __________________________________________________
    __________________________________________________


    Do prefer a nullable type T? to e. g. Option[T]?
    5. Do prefer a nullable type T? to e. g. Option[T]?

    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________
    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________

    Why?
    __________________________________________________
    __________________________________________________
    Why?
    __________________________________________________
    __________________________________________________


    Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]:
    ________________________________________________________________________________
    ________________________________________________________________________________
    ________________________________________________________________________________
    6. Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]:
    ________________________________________________________________________________
    ________________________________________________________________________________
    ________________________________________________________________________________


    Given the following declarations ...
    7. Given the following declarations ...

    trait T
    object A extends T
    object B extends T
    trait T
    object A extends T
    object B extends T

    ... what should be the inferred type of
    if (true) A else B
    ... what should be the inferred type of
    if (true) A else B

    ( ) T
    ( ) A|B
    ( ) Other: ______________________________
    ( ) 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: __________________________________________________
    8. 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?
    9. What should be the inferred type of
    if (true) Some(1) else None?

    ( ) Option[Int]
    ( ) Some[Int]|None
    ( ) Option[Int]
    ( ) Some[Int]|None
    ( ) Other: ______________________________


    What should be the inferred type of
    if (true) Nil else List(1).asInstanceOf[::[Int]]?
    10. What should be the inferred type of
    if (true) Nil else List(1).asInstanceOf[::[Int]]?

    ( ) List[Int]
    ( ) Nil|::[Int]
    ( ) Other: ______________________________
    ( ) List[Int]
    ( ) Nil|::[Int]
    ( ) Other: ______________________________


    When, if ever, should a nominal type be preferred to a more precise union type?
    11. 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: ______________________________
    ( ) 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 preferred to a union type?
    12. When should a more precise structural type be preferred to a union type?

    ( ) Always
    ( ) Never
    ( ) Only if the structural type is specified explicitly
    ( ) Other: ______________________________
    ( ) Always
    ( ) Never
    ( ) Only if the structural type is specified explicitly
    ( ) Other: ______________________________


    Given the following declarations ...
    13. 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 = ??? }
    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?
    ... which members are allowed to be called on an instance aOrB of type A|B?

    [ ] aOrB.toString
    [ ] aOrB.foo
    [ ] aOrB.bar
    [ ] aOrB.bippy
    [ ] aOrB.toString
    [ ] aOrB.foo
    [ ] aOrB.bar
    [ ] aOrB.bippy


    How will inference of union types interact with structural types?
    __________________________________________________
    __________________________________________________
    14. How will inference of union types interact with structural types?
    __________________________________________________
    __________________________________________________


    Given the following definitions ...
    15. Given the following definitions ...

    val x: AnyRef { def foo: Int } = null
    val y: AnyRef { def foo: Int } = null
    val x: AnyRef { def foo: Int } = null
    val y: AnyRef { def foo: Int } = null

    ... should it be allowed to call xOrY.foo?
    ... should it be allowed to call xOrY.foo?

    ( ) Yes
    ( ) No
    ( ) Other: ______________________________
    ( ) Yes
    ( ) No
    ( ) Other: ______________________________


    Given the following definitions ...
    16. Given the following definitions ...

    val x = new AnyRef { def foo: Int = 23}
    val y = new AnyRef { def foo: Int = 42}
    val x = new AnyRef { def foo: Int = 23}
    val y = new AnyRef { def foo: Int = 42}

    ... should it be allowed to call xOrY.foo?
    ... should it be allowed to call xOrY.foo?

    ( ) Yes
    ( ) No
    ( ) Other: ______________________________
    ( ) Yes
    ( ) No
    ( ) Other: ______________________________


    Will your choice from above break existing, valid code?
    17. Will your choice from above break existing, valid code?

    ( ) Yes
    ( ) Yes, but it doesn't matter because: ______________________________
    ( ) No, because: ______________________________
    ( ) Maybe?
    ( ) Yes
    ( ) Yes, but it doesn't matter because: ______________________________
    ( ) No, because: ______________________________
    ( ) Maybe?


    Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________
    18. Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________


    Please give your typing approach an intuitive name:
    __________________________________________________
    19. Please give your typing approach an intuitive name:
    __________________________________________________


    Please describe the guiding principle of your typing approach in one sentence:
    ________________________________________________________________________________
    ________________________________________________________________________________
    20. Please describe the guiding principle of your typing approach in one sentence:
    ________________________________________________________________________________
    ________________________________________________________________________________

  6. soc renamed this gist Jun 14, 2013. 1 changed file with 66 additions and 7 deletions.
    73 changes: 66 additions & 7 deletions gistfile1.txt → The Union Type Quiz
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    Union type quiz
    ===============
    The Union Type Quiz
    ===================

    Should there be predefined implicit widening conversions between numbers?

    @@ -26,6 +26,36 @@ What should be the inferred type of the expression
    ( ) Other: ______________________________


    Do you prefer a union type A|B to Either[A, B]?

    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________

    Why?
    __________________________________________________
    __________________________________________________


    Do prefer a nullable type T? to e. g. Option[T]?

    ( ) Always
    ( ) Never
    ( ) Sometimes: ______________________________
    ( ) Other: ______________________________

    Why?
    __________________________________________________
    __________________________________________________


    Explain why your answer to A|B vs. Either[A, B] is consistent and intuitive with your answer to T? vs. Option[T]:
    ________________________________________________________________________________
    ________________________________________________________________________________
    ________________________________________________________________________________


    Given the following declarations ...

    trait T
    @@ -68,15 +98,15 @@ What should be the inferred type of
    ( ) Other: ______________________________


    When, if ever, should a nominal type be prefered to a more precise union type?
    When, if ever, 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: ______________________________


    When, if ever, should a more precise structural type be prefered to a union type?
    When, if ever, should a more precise structural type be preferred to a union type?

    ( ) Always
    ( ) Never
    @@ -98,6 +128,35 @@ Given the following declarations ...
    [ ] aOrB.bippy


    How will inference of union types interact with structural types?
    __________________________________________________
    __________________________________________________


    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: ______________________________


    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: ______________________________


    Will your choice from above break existing, valid code?

    ( ) Yes
    @@ -106,9 +165,9 @@ Will your choice from above break existing, valid code?
    ( ) Maybe?


    How will inference interact with structural types?
    __________________________________________________
    __________________________________________________
    Will your design make a difference whether a type has been inferred and has been specified explicitly?
    ________________________________________________________________________________
    ________________________________________________________________________________


    Please give your typing approach an intuitive name:
  7. soc revised this gist Jun 13, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -83,6 +83,7 @@ When, if ever, should a more precise structural type be prefered to a union type
    ( ) Only if the structural type is specified explicitly
    ( ) Other: ______________________________


    Given the following declarations ...

    trait T { def foo: Int }
    @@ -109,9 +110,11 @@ 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:
    ________________________________________________________________________________
    ________________________________________________________________________________
  8. soc created this gist Jun 13, 2013.
    118 changes: 118 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,118 @@
    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:
    ________________________________________________________________________________
    ________________________________________________________________________________