3

What does it mean, and also what is the cardinality of the next types for example:

unit->int  

bool->(int->bool)
BenMorel
  • 34,448
  • 50
  • 182
  • 322
rookie
  • 7,723
  • 15
  • 49
  • 59

1 Answers1

2

The cardinality of a type is the number of possible legal values that can be of that type.

With function types, we usually want to consider two functions that return the same value for every input to be "the same function", for cardinality purposes at least (this is known as "extensional equality").

I am assuming that this is a homework problem, and I am further going to assume that functions which don't terminate or yield undefined values are not to be included (as, indeed, they wouldn't be included in a typical mathematical treatment).

Expressing the cardinality of types which can have a finite number of possible values, is fairly easy in principle, because you can just give a number as the cardinality. However, with infinite cardinalities, technically there is a distinction between different kinds of infinities. For example, an uncountable infinity is "larger than" a countable infinity. (To be honest, I am not sure whether you are expected to know this, or whether you are just supposed to give an answer of "infinite" - check your course notes.) For this reason, it's a good idea to specify which infinity you are talking about, e.g. by referring to the cardinality of a "simpler" type.

So the cardinality of unit->int is the same as the cardinality of int (and the same goes for any other destination type which you might choose instead of int), because a value of type unit->X must necessarily be a constant function which "ignores its input" and returns a constant value of type X.

I hope this incomplete answer is enough to get you started.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • @Robin Green: thanks a lot, but what about the second, can I suggest that it is 2 * 2 * #(int)? – rookie Nov 05 '10 at 10:03
  • @Robin Green: this is the problem, that in my notes I have no explanations about infinity, in net I can't find proper info, I know also int has 32 bit, so it can get values from up to 2^32? so what about second? was I right? – rookie Nov 05 '10 at 10:23
  • 1
    @rookie: No, that's not the correct answer. Consider `int->bool`, and let's pretend that there are only 10 integers (haha). The number of functions from int to bool would certainly be more than 20: in fact, it would be 1024. So it's not a matter of simply multiplying two cardinalities, when you have a function type. – Robin Green Nov 05 '10 at 10:26
  • 1
    @rookie: int has 32 bits only in some languages (or platforms: in C it depends on the platform, but I can tell from the syntax that this isn't C!). But if you have been told that int has 32 bits that's fine - then all the stuff about infinity is not relevant to your answer at all. – Robin Green Nov 05 '10 at 10:32
  • @Robin Green: thanks a lot, now I understood, where did You read all this info, will be very grateful for any links, it seems that You passed course about set theory, am I wrong? – rookie Nov 05 '10 at 10:39
  • 1
    @rookie: From various sources. The definition of cardinality can be found on Wikipedia; extensional equality came up a lot in my research (I do research in computer science) but I can't remember a specific source; the `unit->X` reasoning was something I figured out myself. – Robin Green Nov 05 '10 at 11:11