UVA CS 655 - Lecture 14: Types of Types

Unformatted text preview:

PowerPoint PresentationMenuTypesWhy have types?TaxonomyLabrador: BARK with Latent TypesLabrador ProgramOperational Semantics: ADDTyped Register FileOperational Semantics: ADDintegerOperational Semantics: ADDrealStrong vs. Weak TypingManifest TypesMastiff: BARK with Manifest TypesMastiff ProgramInput Function: I: Program  CSTORE Loc IntLiteralIs Dynamic Type Checking Useful?ProjectsFinding a Project TopicExample (Haiyong)If you really can’t find a project related to your researchCourse Project CalendarProject MantrasProject QuestionsStatic SemanticsTyping RulesMastiff Typing RulesTyping ADDTyping MULTyping IFType CheckingType Checking ExampleSummaryChargeDavid Evanshttp://www.cs.virginia.edu/~evansCS655: Programming LanguagesUniversity of VirginiaComputer ScienceLecture 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, 19496 March 2001 CS 655: Lecture 14 2Menu•Latent Types, Dynamic Checking•Manifest Types, Dynamic Checking•Project Kickoff•Manifest Types, Static Checking6 March 2001 CS 655: Lecture 14 3Typesintegers in [0, …)StringsBeatle’s Song Titlespointers that points to integer that is prime numberColorssecret informationpointers that points to pointer that points to storageshared by some other pointerprograms that halt•Type is any set of values •After Spring Break, we will see a different definition...6 March 2001 CS 655: Lecture 14 4Why 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 5Taxonomy•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 6Labrador: 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 Loc2must be the same type, result has same type. | MUL Loc1 Loc2 Loc1 gets the value of Loc1 * Loc2. Loc1 and Loc2must be the same type. | IF Loc1 THEN Loc1 If value in Loc1 is non-zero, jump to instructioncorresponding to value in Loc2. Loc1 and Loc2must contain integers.Literal ::= IntLiteral | RealLiteralIntLiteral ::= [-]?[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 Dogs6 March 2001 CS 655: Lecture 14 7Labrador 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 8Operational Semantics: ADDInstructions[PC] = ADD Loc1 Loc2 < Instructions x PC x RegisterFile >  < Instructions x PC’ x RegisterFile’ >wherePC’ = PC + 1RegisterFile’[n] = RegisterFile[n] if n  LocRegisterFile’[n] = if n  Loc1 RegisterFile[Loc1] + RegisterFile[Loc2]BARK rule:What does this mean?6 March 2001 CS 655: Lecture 14 9Typed Register FileC = Instructions x PC x RegisterFileRegisterFile[i] = <type, value> for all integers itype = integer | realvalue = an integer if type if integer, a real if type is realAssume functions typeof(RegisterFile[i]), valueof(RegisterFile[i])6 March 2001 CS 655: Lecture 14 10Operational Semantics: ADDintegerInstructions[PC] = ADD Loc1 Loc2, < Instructions x PC x RegisterFile >  < Instructions x PC’ x RegisterFile’ >where PC’ = PC + 1RegisterFile’[n] = RegisterFile[n] if n  LocRegisterFile’[n] = if n  Loc1<integer, valueof(RegisterFile[Loc1]) +integer valueof(RegisterFile[Loc2])>typeof(RegisterFile[Loc1]) = integer, typeof(RegisterFile[Loc2]) = integer6 March 2001 CS 655: Lecture 14 11Operational Semantics: ADDrealInstructions[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 + 1RegisterFile’[n] = RegisterFile[n] if n  LocRegisterFile’[n] = if n  Loc1 <real, valueof(RegisterFile[Loc1]) +real valueof(RegisterFile[Loc2])>6 March 2001 CS 655: Lecture 14 12Strong 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 13Manifest TypesOften, 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 & Gifford6 March 2001 CS 655: Lecture 14 14Mastiff: BARK with Manifest TypesProgram ::= 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 musthave been declared with the sametype as Literal. … (same as Labrador)Mastiff: An excellent guard dog, yet gentle and affectionate to its family.Walter & Shackles Guide to Dogs6 March 2001 CS 655: Lecture 14 15Mastiff Program[D0] TYPE R0 REAL[D1] TYPE R1 INTEGER[0] STORE R0 3.14159[1] STORE R1 4[2] MUL R1 R1[3] MUL R0 R16 March 2001 CS 655: Lecture 14 16Input Function: I: Program  CC = Instructions x PC x RegisterFile whereInstructions = same as before, PC =


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 2 2 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?