Lecture1 ValuesTypes
Lecture1 ValuesTypes
• In C programming:
enum Month = {jan, feb, mar, apr, may, jun, jul, aug, sep,
oct, nov, dec};
struct Date{
Month m;
byte d;
}
Mappings
• The concept of mapping underlies two
language features (arrays and
functions/methods)
• What does mean?
– is a mapping from to
– maps every value in to a value in
– What is the cardinality of ?
• Consider some examples
Mappings
• represents the set of all mappings from to
• Consider some examples.
• What is the cardinality of ?
Arrays implementing Mappings
• An array is an indexed sequence of
components
• An array has one component of type for each
value of type
• The length of an array is the number of its
components, which is # .
• The type must be finite
• Consider some examples
Functions implementing Mappings
• Consider the following function/method:
boolean isEven (int n){
return (n%2 ==0);
}
• What mapping does isEven implement? i.e.
What are the pairs of elements?
• What is the type of the mapping? i.e. The
mapping is from set ? to set ?
Functions implementing Mappings
• Consider a function/method with multiple
parameters
float power(float b, int n){
…
}
• What mapping does the method power
implement?
• What is the type of the mapping implemented
by the power function/method?
Summary
• What is a type?
• What distinguishes a type?
• What is a primitive type?
• What is a composite type?
• What are the underlying concepts for each type we
have seen?
– A primitive type
– A composite type such as a struct in C
– An array type
– A function type
Reading
• Chapter 2: Programming Language Design
Concepts