### math

#### type a = {X:int; Y:int} vs type a = |X of int |Y of int

```I'm really more interested in the theoretical-set answer. So maybe I should ask int * int vs int + int. I interpret int * int as a tuple with cardinal of int squared as the number of combinations.
```
```If you want to find out more about the theory, you can search for information about product types (tuples are a basic case, records are labeled products) and sum types (the Choice<..> type in F# is a basic case, discriminated unions are labeled sum types).
The set-theoretical interpretation is that product types correspond to product of sets and sum types correspond to a union (more precisely to a disjoint union - because they are labeled).
So, assuming that [| T |] is a set representing values of a type T:
[| T1 * T2 |] = { (v1, v2) | v1 ∈ [| T1 |], v2 ∈ [| T2 |] }
[| T1 + T2 |] = { (1, v) | v ∈ [| T1 |] } ∪ { (2, v) | v ∈ [| T2 |] }
A simpler version of the + operation would be just union, but that only makes sense when the two types have distinct values (and so you can distinguish between without the labels):
[| T1 + T2 |] = [| T1 |] ∪ [| T2 |]
This is actually quite fun, because you can find out that many of the standard algebraic laws will work for types too. For example, distributivity says that: (a + b) * c = (a * c) + (b * c). This works for types too and it means that the following two are equivalent:
type AorB = A of int | B of string // int + string
type AorBandC = AorB * float // (int + string) * float
type AandC = int * float // int * float
type BandC = string * float // string * float
type AandCorBandC = AC of AandC | BC of BandC // (int * float) + (string * float)
You can write a pair of functions that will map between the values of AorBandC and AandCorBandC. In fact, you can go even wilder and even differentiate types. This is a bit crazy, but you asked for a theory: http://www.cs.nott.ac.uk/~txa/publ/jpartial.pdf
```
`Yes, record types are just like tuple types, except that their elements have names. As the F#/ML syntax for tuples types suggests, a tuple of type A * B * C * ... has |A| * |B| * |C| * ... possible values. Likewise, you are also right that a discriminated union | N1 of A | N2 of B | ... has |A| + |B| + ... possible values. You didn't mention it, but function types correspond to exponentiation: A -> B has |B||A| inhabitants.`

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App