PL Data Types (1)
PL Data Types (1)
University of Zimbabwe
Facilitator: G. Mhlanga
+263775190786
29/10/2024
Programming
Languages
Data Types
Most programming languages require the
programmer to declare the data type of every data
object, and most database systems require the user
to specify the type of each data field.
Available data types vary from one
programming language to another, and from
one database application to another, but the
following usually exist in one form or another:
integer: In more common parlance, whole number; a number that
has no fractional part.
floating-point: A number with a decimal point. For example, 3 is
an integer, but 3.5 is a floating-point number.
character(text ): Readable text
Purpose of Types in a Programming Language
Types provide implicit context for many
operations, so that the programmer
does not have to specify that type
explicitly
For example in C, the expression a + b
Uses integer addition if a and b are of
integer type
Uses floating pointing addition if a and b
are of double type
Type Systems
A type system consists of:
A mechanism to define types and associate
them with certain language constructs
A set of rules for type equivalence, type
compatibility and type inference
Typeequivalence rules determine when the types
of two values are the same
Typecompatibility rules determine when a value of
a given type can be used in a given context
Type information allows the language to limit the
set of acceptable values to those that provide a
particular subroutine interface
Type Checking
The process of ensuring that a program obeys the language’s typical
compatibility rules
A violation of the rules is known as a type clash
A language is said to be strongly-typed if it prohibits in a way that the
language can enforce, the application of any operation to any object
that is not intended to support that operation
A language is said to be statically typed if it is strongly typed and
type checking can be performed at compile time
Ex: Ada is strongly type and for the most part statically typed
Ex: Pascal can do most of its type checking at compile time,
though the language not quite strongly type: untagged variant
records are its only loophole
Polymorphism allows a single body of code to work with objects of
multiple types. It may or may not imply the need for run-time type
checking
Because the types of objects can be thought of as implied
(unspecified) parameters, dynamic typing is said to support
implicit parametric polymorphism
The Meaning of “Type”
Type can be thought of in 3 points of view:
Denotational Point of View
A type is simply a set of values
Constructive Point of View
A type is either one of a small collection of built-in types (integer,
character, Boolean, real, etc; also called primitive or predefined
types), or a composite type created by applying a constructor (record,
set, array, etc) to one or more simpler types
Abstraction-based Point of View
A type is an interface consisting of a set of operations with well-
defined and mutually consistent semantics