types - Types Classification of Values cs3723 1 Outline...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
cs3723 1 Types Classification of Values
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 2 Outline General discussion of types What is a type? Compile-time vs run-time type checking Conservative program analysis Type inference Good example of static analysis algorithm Will study algorithm and examples Polymorphism Polymorphism vs overloading Uniform vs non-uniform impl of polymorphism
Background image of page 2
cs3723 3 Type A type is a collection of computable values that share some structural property. Examples Integers Strings int ->bool (int ->int) -> bool “Non-examples” {3, true, λ x.x} Even integers {f:int -> int | if x > 3 then f(x)>x*x+1} Distinction between sets that are types and sets that are not types is language dependent.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 4 Types in Programming A type is a collection of computable values Represent concepts from problem domain Accounts, banks, employees, students Represent different implementation of values Integers, strings, floating points, lists, records, tuples … Languages use types to Support organization of concepts Separate types for separate concepts from problem domain Identify and prevent errors Compile-time and run-time type checking Prevent meaningless computation 3 + true - “Bill” Support efficient translation (by compilers) Short integers require fewer bits Access record component by a known offset Use integer units for integer operations
Background image of page 4
cs3723 5 Values and Types Basic types: types of atomic values int, bool, character, real, symbol Values of different types have different layouts have different operations Explicit vs. implicit type conversion of values Compound types: types of compound values List, record, array, tuple, struct, ref, pointer Built from type constructors int arr[100] arr: array(int,100) (3, 4, “abc”) : int * int * string int *x x : pointer(int) int f(int x) { return x + 5} f : int int
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 6 Type Declaration and equivalence Type declarations Provide ways to introduce new types (user-defined types) Transparent declarations Introduce a synonym for another type typedef struct { int a, b; } mystruct; typedef mystruct yourstruct; Opaque declarations Introduce a new type struct XYZ { int a, b,c; }; Type equivalence: struct s {int a,b; } = struct t {int a,b; } ? Structural equivalence: yes s and t are the same basic type or s and t are built using the same compound type constructor with the same components Name equivalence: no S and t are different names Names uniquely define compound type expressions In C, name equivalence for records/structs, structural equivalence for all other types
Background image of page 6
cs3723 7 The Type System Each language has a type system that includes A collection of basic types and compound types Type declaration rules on how to introduce new types For each basic/compound type, rules on
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

types - Types Classification of Values cs3723 1 Outline...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online