DOC PREVIEW
UVA CS 655 - Lecture 14: Types of Types

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 14 Types of Types It would appear that we have reached the limits of what it is possible to achieve with computer technology although one should be careful with such statements as they tend to sound pretty silly in five years John Von Neumann 1949 CS655 Programming Languages University of Virginia David Evans Computer Science http www cs virginia edu evans Menu Latent Types Dynamic Checking Manifest Types Dynamic Checking Project Kickoff Manifest Types Static Checking 6 March 2001 CS 655 Lecture 14 2 Types integers in 0 Strings Beatle s Song Titles Colors secret information programs that halt pointers that points to integer that is prime number pointers that points to pointer that points to storage shared by some other pointer Type is any set of values After Spring Break we will see a different definition 6 March 2001 CS 655 Lecture 14 3 Why have types Overloading operators vs FADD compiler needs types to figure out what means Detecting program errors Better to notice error than report incorrect result Make programs easier to read understand and maintain Better than comments if they are checked and can be trusted Security Can use types to constrain the behavior of programs we ll see Proof Carrying Code later 6 March 2001 CS 655 Lecture 14 4 Taxonomy Latent vs Manifest Are types visible in the program text Checked statically vs checked dynamically Do you have to run the program to know if it has type errors Checked weakly vs strongly How strict are the rules for using types Meaningless just matter of degree All combinations are theoretically possible Language that is manifest static weak Language that is latent dynamic strong 6 March 2001 CS 655 Lecture 14 5 Labrador BARK with Latent Types Instruction STORE Loc Literal HALT ERROR Same as BARK ADD Loc1 Loc2 Loc1 gets the value of Loc1 Loc2 Loc1 and Loc2 must be the same type result has same type MUL Loc1 Loc2 Loc1 gets the value of Loc1 Loc2 Loc1 and Loc2 must be the same type IF Loc1 THEN Loc1 If value in Loc1 is non zero jump to instruction corresponding to value in Loc2 Loc1 and Loc2 must contain integers Literal IntLiteral RealLiteral IntLiteral 0 9 0 9 Has type integer RealLiteral 0 9 0 9 0 9 Has type real As companions Labradors are kindly patient intelligent and always keen to please They make perfect family dogs being especially good with children Walter Shackles Guide to Dogs 6 March 2001 CS 655 Lecture 14 6 Labrador Program 0 STORE R0 3 14159 1 STORE R1 4 2 MUL R1 R1 3 MUL R0 R1 6 March 2001 CS 655 Lecture 14 7 Operational Semantics ADD BARK rule Instructions PC ADD Loc1 Loc2 Instructions x PC x RegisterFile Instructions x PC x RegisterFile where PC PC 1 RegisterFile n RegisterFile n if n Loc RegisterFile n if n Loc1 RegisterFile Loc1 RegisterFile Loc What does this 2mean 6 March 2001 CS 655 Lecture 14 8 Typed Register File C Instructions x PC x RegisterFile RegisterFile i type value for all integers i type integer real value an integer if type if integer a real if type is real Assume functions typeof RegisterFile i valueof RegisterFile i 6 March 2001 CS 655 Lecture 14 9 Operational Semantics ADDinteger Instructions PC ADD Loc1 Loc2 typeof RegisterFile Loc1 integer typeof RegisterFile Loc2 integer Instructions x PC x RegisterFile Instructions x PC x RegisterFile where PC PC 1 RegisterFile n RegisterFile n RegisterFile n if n Loc if n Loc1 integer valueof RegisterFile Loc1 integer valueof RegisterFile Loc2 6 March 2001 CS 655 Lecture 14 10 Operational Semantics ADDreal Instructions PC ADD Loc1 Loc2 typeof RegisterFile Loc1 real typeof RegisterFile Loc2 real Instructions x PC x RegisterFile Instructions x PC x RegisterFile where PC PC 1 RegisterFile n RegisterFile n RegisterFile n real valueof RegisterFile Loc1 real valueof RegisterFile Loc2 6 March 2001 CS 655 Lecture 14 if n Loc if n Loc1 11 Strong vs Weak Typing What do we have Latent dynamic strongly typed language To get latent dynamic weakly typed language Allow ADD and MUL to work on mixed types result is real allow IF predicate to be real Add transition rules for Instructions PC ADD Loc1 Loc2 typeof RegisterFile Loc1 real typeof RegisterFile Loc2 integer etc 6 March 2001 CS 655 Lecture 14 12 Manifest Types Often however explicit manifest types make programs easier for compilers to read not easier for humans to read and explicit manifest types are generally cumbersome for the program writer as well Implicitly latently typed programming languages thus have clear advantages in terms of readability and writability Turbak Gifford 6 March 2001 CS 655 Lecture 14 13 Mastiff BARK with Manifest Types Program Declaration Instruction Declaration TYPE Loc INTEGER Loc will hold integral values TYPE Loc REAL Loc will hold real values Instruction STORE Loc Literal Loc gets the value of Literal Loc must have been declared with the same type as Literal same as Labrador Mastiff An excellent guard dog yet gentle and affectionate to its family Walter Shackles Guide to Dogs 6 March 2001 CS 655 Lecture 14 14 Mastiff Program D0 D1 0 1 2 3 TYPE R0 REAL TYPE R1 INTEGER STORE R0 3 14159 STORE R1 4 MUL R1 R1 MUL R0 R1 6 March 2001 CS 655 Lecture 14 15 Input Function I Program C C Instructions x PC x RegisterFile where Instructions same as before PC 0 RegisterFile n integer 0 if TYPE Rn INTEGER is in Declarations RegisterFile n real 0 0 if TYPE Rn REAL is in Declarations RegisterFile n undeclared 0 for all other integers n RegisterFile n error 0 if TYPE Rn INTEGER and TYPE Rn REAL are in Declarations 6 March 2001 CS 655 Lecture 14 16 STORE Loc IntLiteral Instructions PC STORE Loc IntLiteral typeof RegisterFile Loc integer Instructions x PC x RegisterFile Instructions x PC x RegisterFile where PC PC 1 RegisterFile n RegisterFile n if n Loc RegisterFile n integer value of IntLiteral if n Loc 6 March 2001 CS 655 Lecture 14 17 Is Dynamic Type Checking Useful 6 March 2001 CS 655 Lecture 14 18 Projects Ideal Project Should 1 Contribute to your thesis research work 2 Lead to a conference paper 3 Involve something interesting related to programming languages 4 Not take up all of your time for the rest of the semester Not all projects will be ideal 1 is beneficial 2 is optimistic 3 is required 4 is optional 6 March 2001 CS 655 Lecture 14 19 Finding a Project Topic Think about how your research relates to programming languages Are there things that you describe in an ad hoc way today that could be better understood if they were described more precisely Are the places where new abstractions or


View Full Document

UVA CS 655 - Lecture 14: Types of Types

Download Lecture 14: Types of Types
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 14: Types of Types and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 14: Types of Types and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?