06 - Click to edit Master subtitle style Chapter Six Modern...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Click to edit Master subtitle style Chapter Six Modern Programming Languages, 2nd ed. Types Chapter Six Modern Programming Languages, 2nd ed. 11 Chapter Six Modern Programming Languages, 2nd ed. A Type Is A Set When you declare that a variable has a certain type, you are saying that the values the variable can have are elements of a certain set A type is a set of values plus a low-level representation plus a collection of operations that can be applied to those values Chapter Six Modern Programming Languages, 2nd ed. 22 int n; Chapter Six Modern Programming Languages, 2nd ed. Today: A Tour Of Types There are too many to cover them all Instead, a short tour of the type menagerie Most ways you can construct a set in mathematics are also ways to construct a type in some programming language We will organize the tour around that connection Chapter Six Modern Programming Languages, 2nd ed. 33 Chapter Six Modern Programming Languages, 2nd ed. Outline Type Menagerie Primitive types Constructed types Uses For Types Type annotations and type inference Type checking Type equivalence issues Chapter Six Modern Programming Languages, 2nd ed. 44 Chapter Six Modern Programming Languages, 2nd ed. Primitive vs. Constructed Types Any type that a program can use but cannot define for itself is a primitive type in the language Any type that a program can define for itself (using the primitive types) is a constructed type Some primitive types in ML: int , real , char An ML program cannot define a type named int that works like the predefined int A constructed type: int list Defined using the primitive type int and the list type constructor Chapter Six Modern Programming Languages, 2nd ed. 55 Chapter Six Modern Programming Languages, 2nd ed. Primitive Types The definition of a language says what the primitive types are Some languages define the primitive types more strictly than others: Some define the primitive types exactly (Java) Others leave some wiggle roomthe primitive types may be different sets in different implementations of the language (C, ML) Chapter Six Modern Programming Languages, 2nd ed. 66 Chapter Six Modern Programming Languages, 2nd ed. Comparing Integral Types Chapter Six Modern Programming Languages, 2nd ed. 77 C: char unsigned char short int unsigned short int int unsigned int long int unsigned long int No standard implementation, but longer sizes must provide at least as much range as shorter sizes. Java: byte (1-byte signed) char (2-byte unsigned) short (2-byte signed) int (4-byte signed) long (8-byte signed) Scheme: integer Integers of unbounded range Chapter Six Modern Programming Languages, 2nd ed....
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 62

06 - Click to edit Master subtitle style Chapter Six Modern...

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

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