For data types (Chapters 7 & 8)

Ace your homework & exams now with Quizwiz!

List and describe the components of a type system. Explain what happens when a violation occurs.

A mechanism to define types and associate them with certain language constructs. A set of rules for checking Type equivalence - determine when the types of two objects are the same. Type compatibility - determine when an object of a given type can be used in a given context. Type inference - determine the type of an expression based on the types of its constituent parts or (sometimes) the surrounding context. A violation of the rules is known as type clashing.

Static Typing

A type system where types are checked at compile time, rather than at run time

- Explain array slices and their purpose.

An array slice is a rectangular portion of an array. Slices are useful because they only allow you to grab a subset of the array.

Type Conversion

An explicit function call that takes a value of one type and computes a corresponding value of another type.

Implicit Parametric Polymorphism

Any expression whose type remains incompletely specified after inference is automatically polymorphic Avoids the disadvantage of the need for run-time checking, which incurs nontrivial costs and delays the reporting of errors.

- Summarize the arguments for and against coercion.

For - It's a natural way in which to support abstraction and program extensibility, by making it easier to use new types in conjunction with existing ones. Against - It allows types to be mixed without an explicit indication of intent on the part of the programmer, it represents a significant weakening of type security.

- Explain the distinction between implicit and explicit parametric polymorphism. What are their comparative advantages?

Implicit Parametric Polymorphism - Avoids the disadvantage of the need for run-time checking, which incurs nontrivial costs and delays the reporting of errors. Explicit Parametric Polymorphism - Allows the programmer to specify type parameters when declaring a subroutine or class.

- Give examples of languages with implicit and explicit parametric polymorphism.

Implicit Parametric Polymorphism - ML-family languages. Explicit Parametric Polymorphism - Compiled languages.

Explain the purpose of types in programming languages.

Implicit context Checking - make sure certain meaningless operations do not occur -Type checking cannot prevent all meaningless operations -It catches enough of them to be useful

Give examples of scalar and non-scalar data types.

Integers, Booleans, and characters are all examples of discrete types Discrete, rational, real, and complex types together constitute the scalar types. Nonscalar types are usually called composite types. Options are arguably the simplest composite types. common composite types include records (structures), variant records (unions), arrays, sets, pointers, lists, and files.

- Discuss the comparative advantages of structural and name equivalence for types.

Name Equivalence - the advantages are its high level and usually makes more sense to the programmer. If it is named something different the programmer many times means for the structures to be different. Structural Equivalence - this is a low level equivalence. It would make more logical sense for the computer to analyze these as being the same objects because of the underlying similarities.

- Explain the differences between shallow and deep comparisons.

Shallow Comparisons - refer to the same object. Deep Comparisons - refer to equal objects.

- Explain the difference between strict and loose name equivalence.

Strict name equivalence is when aliases are considered distinct (strictly based on name). Loose name equivalence is when aliases are considered equivalent (underlying data type).

- Explain the concepts of strong, weak, static, and dynamic typing.

Strong - never allows an operation to be applied to an object that does not support it. Weak - variables are not bound to a specific data type. Static - Something enforces strong typing at compile time. Dynamic - a form of late binding, delays issues and typing until run time.

- Describe the differences between two-dimensional arrays and arrays of one-dimensional arrays.

The difference between 2D arrays and 1D arrays are the way they are stored in memory and the way the data is accessed.

- List and discuss differences between records and arrays.

The differences between records and arrays are records are heterogeneous, meaning they can store different data types and arrays are homogeneous, meaning they store all the same data types.

- Discuss the significance of "holes" in records, explain why they arise, and what problems they cause.

The significance of "holes" in records is it creates unused space. Holes in records arise when there is an allocated amount of memory for a specific thing that's not used in the program. The problems holes in records cause are an abundance of unused memory.

- Explain the differences among type conversion, type coercion, and non-converting type casts.

Type Conversion - If the programmer wishes to use a value of one type in a context that expects another. Type Coercion - Whenever a language allows a value of one type to be used in a context that expects another, the language implementation must perform an automatic, implicit conversion to the expected type. Non-converting Type Casts - A change of type that does not alter the underlying bits.

Type Equivalence

the method used to determine whether two types are equivalent, e.g. name equivalence or structural equivalence.

Name Equivalence

type equivalence testing in which two types are considered equal only if they have the same name. cf. structural equivalence.

Type Compatibility

varies from language to langue. It refers to the similarity between two types of objects.

Denotational approach

views types as a collection of values from a "domain".

Abstraction approach

views types as the collection of well-defined operations that can be applied to objects of that type.

Structural approach

views types as the internal structure of the data, described down to the level of a small set of fundamental types.

Type Coercion

when a value of one data type is implicitly (automatically) changed to another data type

Describe three contexts in which type inference occurs.

- The result of an arithmetic operator usually has the same type as the operands (possibly after coercing one of them, if their types were not the same). - The result of a comparison is usually Boolean. - The result of a function call has the type declared in the function's header. - The result of an assignment (in languages in which assignments are expressions) has the same type as the left-hand side.

Non-converting Type Casts

A change of type that does not alter the underlying bits.

- Explain what it means for a type system to be orthogonal.

A collection of features is _______________ if there are no restrictions on the ways in which the features can be combined (analogy to vectors)

Explicit Parametric Polymorphism

Allows the programmer to specify type parameters when declaring a subroutine or class.

Explain the type system used at the hardware level.

Computer hardware can interpret bits in memory in several different ways: as instructions, addresses, characters, and integer and floating-point numbers of various lengths. The bits themselves, however, are untyped: the hardware on most machines makes no attempt to keep track of which interpretations correspond to which locations in memory.

- Describe the differences between different views of types.

Denotational approach views types as a collection of values from a "domain". Structural approach views types as the internal structure of the data, described down to the level of a small set of fundamental types. Abstraction approach views types as the collection of well-defined operations that can be applied to objects of that type.

- Explain the difference between type equivalence and type compatibility.

Type Equivalence - there's two ways of defining type equivalence; name equivalence and structural. Type Compatibility - varies from language to langue. It refers to the similarity between two types of objects. The difference is equivalence is a tighter relationship than compatibility. Equivalence is when the object can be used if its type and the type expected by the context are equivalent, that is, the data type of the object is same as that expected. Type Compatibility determines where an objects of a certain type can be used, that is, it tells what kind of data can be held in the object depending on the compatibility of its type.

- Under what circumstances does a type conversion require a run-time check?

Types have different sets of values, but the intersecting values are represented in the same way. Checked at run time: use unchanged, or dynamic semantic error. The types have different low-level representations, but some sort of correspondence among their values can be defined Example: int ⇒ float; code executed at run time.

Weak Typing

Variables are not bound to a specific data type.

- Explain what is packing and discuss its advantages and disadvantages.

_________ is when the user specifies the record type. The advantages are the user having control of the data type. The disadvantages are the type not being specified correctly or efficiently.

- What is duck typing? What is its connection to polymorphism? In what languages does it appear?

_________ means if it walks like a duck and quacks like a duck then it must be a duck. This is an operational style of type checking. The connection to ________ is it being the way Object-Oriented PLs are typed. It appears in languages like Java.

- What is type inference?

_____________ refers to the automatic detection of the data type of an expression in a programming language.

Structural Equivalence

a form of type checking in which two types are considered to be equivalent if they have the same basic data type, or if they have the same kind of structure whose components are structurally equivalent. cf. name equivalence.

Dynamic Typing

determines the type of objects as a program executes

Strong Typing

each variable is assigned a type, and only values of that type can be stored in the variable


Related study sets

Ch.22- Lymphatic System and Immunity

View Set

Chapter 3 Prenatal development and birth

View Set

Building Materials, Fasteners, and Adhesives

View Set

Meaning of Extension in other Countries

View Set

Psychology Brain States & Consciousness

View Set

All season driving school final test 2

View Set

PSY 200 Study Guide- Mr Nichols, NWSCC

View Set

Chapter 8 History Layup Questions

View Set

Seeley's Anatomy & Physiology 11th ed Chapter 15

View Set

McFarland USA Important Vocab Words

View Set