2 ms·
How does this type inference stuff work? Is the if expression overloaded in this case? Or does if always return the disjunction of two types in swift? In othe
by arianvanp 7y ago
How does this type inference stuff work? Is the if expression overloaded in this case? Or does if always return the disjunction of two types in swift?
In other languages like rust and Haskell, the branches of if need to agree on their type so I found this a bit confusing.
Is there some kind of embedded DSL stuff going on here?
- favorited 7y ago> Is there some kind of embedded DSL stuff going on here? Exactly. It's a (at this point, unofficial) Swift feature called "function builders." The types end up being the same, because the conditionals are represented as wrapper types. So if count == 0 { EmptyView() } else { Text("\(count)") } would result in a type something like `Conditional<EmptyView, Text>`. https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5...