Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming languages (2/e): Chapter 5a - Tucker, Noonan
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chapter 5 - Types. A language's types denote the kinds of values that programs can manipulate: simple types, structured types, and more complex types. Among the simple types are integers, decimal numbers, characters, and boolean values. Structured types include character strings, lists, trees, and hash tables. More complex types include functions and classes. Types are more fully discussed in Chapter 5. | Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming; they make it digestible. Robin Milner 5.1 Type Errors 5.2 Static and Dynamic Typing 5.3 Basic Types 5.4 NonBasic Types 5.5 Recursive Data Types 5.6 Functions as Types 5.7 Type Equivalence 5.8 Subtypes 5.9 Polymorphism and Generics 5.10 Programmer-Defined Types A type is a collection of values and operations on those values. Example: Integer type has values ., -2, -1, 0, 1, 2, . and operations +, -, *, /, <, . The Boolean type has values true and false and operations , , . Computer types have a finite number of values due to fixed size allocation; problematic for numeric types. Exceptions: Smalltalk uses unbounded fractions. Haskell type Integer represents unbounded integers. Floating point problems? Even more problematic is fixed sized floating point numbers: 0.2 is not exact in binary. So 0.2 * 5 is not exactly 1.0 Floating point is inconsistent with real numbers in mathematics. In the early languages, Fortran, Algol, Cobol, all of the types were built in. If needed a type color, could use integers; but what does it mean to multiply two colors. Purpose of types in programming languages is to provide ways of effectively modeling a problem solution. 5.1 Type Errors Machine data carries no type information. Basically, just a sequence of bits. Example: 0100 0000 0101 1000 0000 0000 0000 0000 0100 0000 0101 1000 0000 0000 0000 0000 The floating point number 3.375 The 32-bit integer 1,079,508,992 Two 16-bit integers 16472 and 0 Four ASCII characters: @ X NUL NUL A type error is any error that arises because an operation is attempted on a data type for which it is undefined. Type errors are common in assembly language programming. High level languages reduce the number of type errors. A type system provides a basis for detecting type errors. 5.2 Static and Dynamic Typing A type system imposes constraints such as the values used in an addition must be | Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming; they make it digestible. Robin Milner 5.1 Type Errors 5.2 Static and Dynamic Typing 5.3 Basic Types 5.4 NonBasic Types 5.5 Recursive Data Types 5.6 Functions as Types 5.7 Type Equivalence 5.8 Subtypes 5.9 Polymorphism and Generics 5.10 Programmer-Defined Types A type is a collection of values and operations on those values. Example: Integer type has values ., -2, -1, 0, 1, 2, . and operations +, -, *, /, <, . The Boolean type has values true and false and operations , , . Computer types have a finite number of values due to fixed size allocation; problematic for numeric types. Exceptions: Smalltalk uses unbounded fractions. Haskell type Integer represents unbounded integers. Floating point problems? Even more problematic is fixed sized floating point numbers: 0.2 is not exact in binary. So 0.2 * 5 is not exactly 1.0 Floating point is inconsistent with real numbers