} enum State { case highlighted case normal case selected } struct Component { let enabled: Bool // 2 let state: State // 3 let theme: Theme // 2 } // Bool * State * Theme = 2 * 3 * 2 = 12 13
Int // result が定義されていないのでコンパイルはできない for x in xs { result += x } return result } func product(_ xs: [Int]) -> Int { var result: Int // こちらも同じ。しかし、result には何を⼊れるべきなのか? for x in xs { result *= x } return result } 27
Int = 0 // 空の和型なので 0 を初期値とする for x in xs { result += x } return result } func product(_ xs: [Int]) -> Int { var result: Int = 1 // 空の積型なので 1 を初期値とする for x in xs { result *= x } return result } 31
型の世界では ↓ のようになる // Never = 0 // A * Never = Never = Never * A つまり、型の世界において struct のフィールドに Never を⼊れる と、その構造体⾃体が Never 型になってしまうという結果になる これは構造体を完全に消滅させることを意味する 34
Exponents Ole Begemann: Making illegal states unrepresentable If a response from the server is received, regardless of whether the request completes successfully or fails, the response parameter contains that information. “ “ 49