Types Flashcards
What is the purpose of types in a language?
- Provide implicit context for operations
- Meaning of + depends on type
- Limits the set of operations that can be performed on a semaantically valid program
What is a type system?
- A mechanism to define types
- A way to associate types with objects in a language
- Sets rules for
- Type equivalence
- Type compatibility
- Type inference
What is type checking?
Process of ensuring that a program satisfies languages type compatibility rules.
What is strongly typed?
Language implementation prohibits application of operation to object not intended to support operation.
What is statically typed?
Strongly typed + type checking (mostly) performed before run-time.
What is dynamically typed?
Type checking performed at run-time.
Describe denotional types.
- Focuses on the value of the type.
- A type is a set of values called a domain.
- A value has a type if it belongs to the set
- An object has a type if its value is guaranteed to be in the set.
Describe constructive types.
Focuses on the construction.
A type is either
- A primitive (built-in) type
- int,
- char,
- boolean,
- etc.
- Or a composite formed by applying a type constructor to simpler types
Describe abstraction-based type?
Focuses on the operations that can be performed on the type.
A type is an interface consisting of a set of operations with well-defined semantics.
What is orthogonality?
There are no restrictions on the way features can be combined in a programming language.
For example
- Pascal is more orthogonal than Fortran, (because it allows arrays of anything, for instance)
- Pascal is not completely orthogonal because it does not permit variant records as arbitrary fields of other records (for instance)
What are primitive types?
Built-in types typically corresponding to those supported by hardware.
What are discrete types?
Countable
- integer
- boolean
- char
- enumeration
- subrange
What are scalar types?
One-dimensional
- discrete
- real
Describe the contents of a record (structures).
Each record is a collection of fields, each of which belongs to a potentially simpler type.
Records are usually laid out contiguously in memory. However, there may be possible holes for alignment reasons. Smart compilers may re-arrange fields to minimize holes. Why could this be an issue?
A programmer may want to arrange fields to keep certain values in the same cache line. Elimminating gaps may cause multiple memory reads for certain full values.
Name a language that allows records to be packed.
Pascal
What are some pros/cons to record packing?
- Optimized for space instead of speed
- Access requires multiple instructions
What are the most common and important composite data types?
Arrays
What is slicing?
A slice or section is a rectangular portion of an array.
What are two lifetime options for arrays?
Global
Local (extend of subroutine)
What are two bound options for arrays?
Static
Dynamic
What are three allocation mechanisms for arrays?
Static
Stack
Heap
When can a compiler allocate space for an array in static global memory?
If the array has a global lifetime and a static shape.
If an array has a local lifetime and a static shape, can its space be allocated in the subroutine’s stack frame at run time?
Explain.
Yes. As long as the exists throughout the execution of a subroutine.