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.

Related Links

prolog in math - searching the level of node in prolog
Applying fast inverse to concatenated 4x4 affine transforms?
In Ada, is there a way to make an enumeration type act like a modulus type — to wrap to 0 after the last of it's range?
Round up to nickel, dime, quarters
Copy a math formula from Word DocX to CkEditor
Is there a difference between (n - (~r % n) - 1) and (n - (abs(r) % n)) when r < 0?
How determine two pairs of numbers are equal
How to find out the sum of products of all combinations of first n natural numbers taken r at a time?n and r are both constants [duplicate]
calculate bounding sphere radius in normalized space
Two positive integers 'a' and 'b' have a sum of 's' and a bitwise XOR of 'x'. How many possible values are there for the ordered pair (a, b)?
How to get the true Euclidean remainder?
How to find position of point that is x unit distant from AB line segment and y unit distant from BC line segment?
Feature based alignment & Non linear least square
Finding the number of times a statement runs
How to calculate distance between several points simultaneously with Euclidean Distance
Division operation is giving me the wrong result

Categories

HOME
common-lisp
dynamics-crm-365
angular2-forms
servlets
rtmp
word-vba
jsonschema
intel-xdk
format
mvvm-light
add-in
superfish
doorkeeper
executable
signature
yii2-advanced-app
orchardcms-1.10
orientdb-2.1
spring-restdocs
revitpythonshell
beanstalkd
opencms
scalability
android-button
laravel-valet
coqide
solarwindslem
mobile-center
django-users
argparse
zipline
flags
bem
jpype
permgen
httpexception
qmenubar
psycopg2
xbrl
complement
kony
reactivex
haste
graph-traversal
hapi.js
agents-jade
network-traffic
uploadify
webmail
sliding
interpreted-language
openocd
python-2.3
protected
gulp-protractor
adserver
chatjs
twill
wmv
xcode6.1.1
deap
loadlibrary
guice-servlet
nsinvocation
mdi
codi
coolstorage
net-ssh
sharepoint-feature
large-teams

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