ln011 - Types A Type is a Set of Values Consider the...

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

View Full Document Right Arrow Icon
Types A Type is a Set of Values Consider the statement: int n; Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values . Also observe that the elements in a type share a common representation: each element is encoded in the same way (float, double, char, etc.) Also, all elements of a type share the same operations the language supports for them. Read Chapter 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
Types Def: A type is a set of values. Def: A primitive type is a type programmer can use but not define. Def: A constructed type is a user defined type. Example: Java, primitive type float q; type float set of all possible floating point values q is of type float, only a value that is a member of the set of all floating point values can be assigned to q.
Background image of page 2
Types Example : ML, primitive type - val p = . ..; untyped variable can assume a value of any type. - - val p:real = . ..; Now p only accepts a value that is the member of the type real.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Types Example: Java, constructed type class Foobar { int i; String s; }; Foobar c = new Foobar(); Now the variable c only accepts values that are members of type Foobar; object instantiations of class Foobar.
Background image of page 4
Example
Background image of page 5

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

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

This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.

Page1 / 15

ln011 - Types A Type is a Set of Values Consider the...

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

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