Get Started. It's Free
or sign up with your email address
Scala types by Mind Map: Scala types

1. Algebraic data types

1.1. Sum types

1.1.1. sealed trait Base case class A() extends Base case class B() extends Base

1.1.1.1. Enums: case class -> case object

1.1.2. Like sum of numbers in algebra: a + b

1.1.3. Contains one value of one member class at a time

1.1.4. With generics: abstract class Either[A, B] case class Left[A] extends Either[A, Nothing] case class Right[B] extends Either[Nothing, B]

1.1.5. Uninhabited type (akin of zero): Nothing

1.2. Product types

1.2.1. Tuples: (A, B, C)

1.2.2. Like product of types in algebra: a*b

1.2.3. Contains one value per each member type at the same time

1.2.4. case class Product(a: Int, b: String)

1.2.5. Empty/unit type (akin of one): ()

2. Classic inheritance

2.1. abstract class A class B extends A

2.2. Type confirmance

2.2.1. Multiple inheritance: class A class B class C extends A with B

2.2.1.1. Overlapping implementation problem

2.2.1.2. Diamond problem

2.2.1.3. Limitations: how many inherited traits, interfaces, abstract classes are possible?

2.3. Types continuum: Any :> AnyRef :> ... :> Nothing

3. Bounds

3.1. Upper bounds

3.2. Lower bounds

3.3. Context and view bounds

3.3.1. Link type system with implicits system

4. Value types

4.1. trait A { type T } class B extends A { type T = Int }

4.1.1. A#T, B#T, new B().T

5. Existential types

5.1. def fun[A](xs: List[A]) -> def fun(xs: List[A] forSome { type T })

5.2. class A[T] forSome { type T <: Number }

6. Structural types

6.1. Ad-hoc polymorphism

6.2. { val x: Int; def fun(x: Int): String = ??? }

6.3. Stricter compile time guarantees

6.3.1. class A { var x: Int } class B extends { var x = 123 } with A

7. Variance

7.1. class Covariant[+A]

7.1.1. A <: B -> Covariant[A] <: Covariant[B]

7.1.2. Output types in functions

7.2. class Contravariant[-B]

7.2.1. A <: B -> Contravariant[A] :> Contravariant[B]

7.2.2. Input types in functions

7.3. class Invariant[A]

7.4. Examples and reasons

8. Type erasure

9. References

9.1. http://www.scala-lang.org/files/archive/spec/2.11/03-types.html

10. Functional types

10.1. A => B (A, B) => C => A

10.2. Method types

10.2.1. (A, B)(C)D