# Scala types Konstantin Stepanov
Get Started. It's Free 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.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?

## 3. 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

## 6. Structural types

### 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 -> Covariant[A] :> Covariant[B]

7.2.2. Input types in functions

## 10. Functional types

### 10.2. Method types

10.2.1. (A, B)(C)D