CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.

Slides:



Advertisements
Similar presentations
CPA: C++ Polymorphism Copyright © 2007 Mohamed Iqbal Pallipurath Overview of C++ Polymorphism Two main kinds of types in C++: native and user-defined –User-defined.
Advertisements

Chapter 7:: Data Types Programming Language Pragmatics
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Type Checking.
Compiler Construction
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
Run time vs. Compile time
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Abstract Data Types and Encapsulation Concepts
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Type Checking and Data Type Implementation (Sections )
Names Variables Type Checking Strong Typing Type Compatibility 1.
CSE 425: Concurrency III Monitors A monitor is a higher level construct for synchronizing multiple threads’ access to a common code segment –Can implement.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
ISBN Chapter 5 Names, Bindings, and Scopes.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
CSE 425: Target Machine Architecture Target Machine Details Many architectures can be similar in overall structure –E.g., Von Neumann with CISC instruction.
Copyright © Curt Hill Structured Data What this course is about.
CSE 425: Syntax II Context Free Grammars and BNF In context free grammars (CFGs), structures are independent of the other structures surrounding them Backus-Naur.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Programming Languages Third Edition Chapter 8 Data Types.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
Overview of C++ Templates
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Homogeneous tuples What are they? –S 2 = S x S –S n = S x S x … x S Cardinalities –#(S 2 )= (#S) 2 –#(S n )= (#S) n –#(S 0 )= (#S) 0 =1 What is S 0 ? –It.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Programming Languages and Design Lecture 6 Names, Scopes and Binding Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 12 – C: structs, linked lists, and casts.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Overview of C++ Polymorphism
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Data Types (1) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Motivation for Generic Programming in C++
Data Types In Text: Chapter 6.
Names and Attributes Names are a key programming language feature
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS 326 Programming Languages, Concepts and Implementation
Iteration Implemented through loop constructs (e.g., in C++)
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Overview of C++ Polymorphism
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via struct member selection operator as in P.x in C++) –Variant records (e.g., unions in C++) let different types overlap in memory Arrays –Usually contiguous in memory and of a homogeneous type Layout and access patterns also may affect cache effects, etc. –Provide an indexing operator (e.g., [] ) to access elements –May be allocated on stack or heap (language specific) –May be compatible with other types (e.g., pointers in C++)

CSE 425: Data Types II Survey of Common Types II “Utility” types (e.g., strings, sets, lists, files) –Widely used but not necessarily inherent to a language itself –Sometimes built into the language (e.g., Pascal) E.g., set operators ( +, *, - ) for union, intersection, and difference –Sometimes provided by a library (e.g., the C++ STL) Strings –Often just an array of characters (e.g., C style char * ) –Often an object with operators (e.g., C++ style string ) Sets (similarly, lists) –Contain unique values (or in the case of lists, ordered sequences) of a common type Files –“Streams” of data coming from and/or going to mass storage

CSE 425: Data Types II Survey of Common Types III Recursive types –May contain (an alias for) another instance of the same type E.g., a list node contains an alias for the next node in the list –May require a pointer or other similar abstraction To halt the nesting (and/or construction) of recursive type instances Pointers and references –Similar in some languages, different in others E.g., pointer/references semantics in Java vs. C++ –Also may be similar to other types E.g., (const) pointer and array semantics in C++ E.g., address arithmetic vs. index arithmetic in C++

CSE 425: Data Types II More about Type Constructors Used to construct sets from other sets –E.g., as Cartesian products (tuples) –If elements are named, a record is projected into its fields (e.g., via struct member selection operator as in P.x in C++) Specialized forms of type constructors are common –Unions often are at best unnecessary in object-oriented languages (or worse: in C++ certain examples can exhibit type problems similar to those seen with reinterpret casting) –Subset type constructors narrow a set (e.g., in Ada to construct a sub-range type from a range type) –Array constructors project an index type into another type –Pointer/reference constructors create aliases for other types (pointers have their own operators but references do not)

CSE 425: Data Types II Type Checking with Polymorphism Hindley-Milner type checking –Strongly typed functional languages (ML and Haskell) do this –Unambiguous (deductive) type inference, by propagating constraints and info up and down an abstract parse tree –Relies on specific forms of instantiation and unification Different types of polymorphism –Parametric (interface) polymorphism –Explicit subtype (inheritance) polymorphism –Liskov substitution principle: whenever S is a subtype of T, wherever you need an instance of T you can use one of S Occurs-check in unification –Makes sure a variable isn’t in an expression substituted for it –Difficult to do efficiently, only use if necessary (it is for H-M)

CSE 425: Data Types II Explicit Polymorphism of Data Relies on syntax to declare forms of polymorphism that cannot be handled implicitly as in previous cases –E.g., declaring polymorphic data structures –Essentially, they provide user-defined type constructors – E.g., in C/C++ function pointer and array typedefs Explicit parametric polymorphism –Explicit declaration of type parameters (e.g., C++ templates) can be used to make data types generic over other types –In C++ calls to function templates are resolved implicitly but template objects require concrete type parameter declaration –Expressions within parameterized functions/methods impose constraints on the parameterized types (concept/models relation in generic programming, see Austern on C++ STL)

CSE 425: Data Types II Today’s Studio Exercises We’ll code up ideas from Scott Chapter , 7.11 –Continuing our exploration of data types from last time Today’s exercises are again in C++ –C++ allows us to explore many type system issues –Please take advantage of the on-line tutorial and reference manual pages that are linked on the course web site –As always, please ask us for help as needed When done, your answers with “Data Types Studio II” in the subject line, to the course account –Send to