tailieunhanh - Lecture Programming languages (2/e): Chapter 5a - Tucker, Noonan

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 Type Errors Static and Dynamic Typing Basic Types NonBasic Types Recursive Data Types Functions as Types Type Equivalence Subtypes Polymorphism and Generics 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: is not exact in binary. So * 5 is not exactly 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. 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 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. 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 Type Errors Static and Dynamic Typing Basic Types NonBasic Types Recursive Data Types Functions as Types Type Equivalence Subtypes Polymorphism and Generics 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: is not exact in binary. So * 5 is not exactly Floating point is inconsistent with real numbers

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.