Arrays as functions. Types. Multidimensional Arrays (row major, column major form) Java arrays

Similar documents
CS201 Discussion 10 DRAWTREE + TRIES

Procedures vs. Functions. Procedure Call. Syntax. Activation Record for Nested Blocks. Environment. CSE 3302 Programming Languages

Data Types. Tour of C. Like Java, Like C. Array Initialization. Array Declaration. Data Types, Arrays, Strings and Pointers in C.

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

How to Design REST API? Written Date : March 23, 2015

Pointers and Arrays. More Pointer Examples. Pointers CS 217

Stack. A list whose end points are pointed by top and bottom

Outline CS 412/413. Function calls. Stack layout. Tiling a call. Two translations

Data sharing in OpenMP

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010

Chapter Spline Method of Interpolation More Examples Electrical Engineering

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers

COMPUTATIONAL INTELLIGENCE

520 Principles of Programming Languages. Memory Management. Memory Management... 35: Garbage Collection

Midterm 2 Sample solution

OPERATION MANUAL. DIGIFORCE 9307 PROFINET Integration into TIA Portal

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Scope, Functions, and Storage Management

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Pointwise convergence need not behave well with respect to standard properties such as continuity.

CURVE FITTING AND DATA REGRESSION

Rational Numbers---Adding Fractions With Like Denominators.

Math/CS 467/667 Programming Assignment 01. Adaptive Gauss Quadrature. q(x)p 4 (x) = 0

APPLICATIONS OF INTEGRATION

Reducing Costs with Duck Typing. Structural

ITEC2620 Introduction to Data Structures

MTH 146 Conics Supplement

From Dependencies to Evaluation Strategies

EECS 281: Homework #4 Due: Thursday, October 7, 2004

Virtual Machine (Part I)

ECE 468/573 Midterm 1 September 28, 2012

Fig.25: the Role of LEX

Functor (1A) Young Won Lim 8/2/17

CS240: Programming in C. Lecture 12: Polymorphic Sorting

Midterm I Solutions CS164, Spring 2006

COMPUTATIONAL INTELLIGENCE

Fall 2017 Midterm Exam 1 October 19, You may not use any books, notes, or electronic devices during this exam.

Functor (1A) Young Won Lim 10/5/17

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

5 Regular 4-Sided Composition

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION

Geometric transformations

9 Graph Cutting Procedures

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

Section 10.4 Hyperbolas

Introduction to Integration

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

MIPS I/O and Interrupt

INTRODUCTION TO SIMPLICIAL COMPLEXES

Improper Integrals. October 4, 2017

Math 464 Fall 2012 Notes on Marginal and Conditional Densities October 18, 2012

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

vcloud Director Service Provider Admin Portal Guide vcloud Director 9.1

Suffix Tries. Slides adapted from the course by Ben Langmead

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

1.5 Extrema and the Mean Value Theorem

Allocator Basics. Dynamic Memory Allocation in the Heap (malloc and free) Allocator Goals: malloc/free. Internal Fragmentation

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

MATH 2530: WORKSHEET 7. x 2 y dz dy dx =

V12 FAMILY BRAND GUIDELINES

1.4 Circuit Theorems

OUTPUT DELIVERY SYSTEM

Misrepresentation of Preferences

Lists in Lisp and Scheme

Engineer To Engineer Note

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Matrices and Systems of Equations

such that the S i cover S, or equivalently S

- 2 U NIX FILES 1. Explin different file types vilble in UNIX or P OSIX s ystem. ( 08 mrks) ( My-08/Dec-08/My-10/My- 12) 2. Wht is n API? How is it di

Engineer To Engineer Note

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Compilers Spring 2013 PRACTICE Midterm Exam

Double Integrals. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Double Integrals

a(e, x) = x. Diagrammatically, this is encoded as the following commutative diagrams / X

)

Very sad code. Abstraction, List, & Cons. CS61A Lecture 7. Happier Code. Goals. Constructors. Constructors 6/29/2011. Selectors.

Study Guide for Exam 3

Ray surface intersections

Introduction to Computer Science, Shimon Schocken, IDC Herzliya. Lecture Writing Classes

Introduction to Julia for Bioinformatics

Math 142, Exam 1 Information.

How. Without. project. your. wanting. personal. Corey. by Galen E

Bruce McCarl's GAMS Newsletter Number 37

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Fuzzy soft -ring. E Blok Esenler, Istanbul, Turkey 2 Department of Mathematics, Marmara University, Istanbul, Turkey

Physics 208: Electricity and Magnetism Exam 1, Secs Feb IMPORTANT. Read these directions carefully:

Solution of Linear Algebraic Equations using the Gauss-Jordan Method

UNIT 11. Query Optimization

Reducing a DFA to a Minimal DFA

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

L2-Python-Data-Structures

Transcription:

Louden Chpters 6,9 Types Dt Types nd Abstrct Dt Types 1 Arrys s functons f: U -> V (f U s ordnl type) f() rry C rrys types cn be wthout szes rry vrbles must hve fxed sze rry_mx( [], sze) // prmeters re essentlly poers { temp, ; ssert(sze > 0); temp = [0]; for (=1; < sze; ++) { f ([] > temp) temp = []; return temp; 2 Jv rrys Jv rrys re hep llocted nd the sze cn be specfed completely dynmclly (but once specfed cn not chnge unless rellocted) clss ArryTest { sttc rry_mx([] ) { temp; temp = [0]; for ( = 1; <.length; ++) { f ([] > temp) temp = []; return temp; u = Integer.prseInt(n.redLne()); [] x = new [u]; Multdmensonl Arrys (row mjor, column mjor form) x[10][20]; /* c code */ rry_mx( [][20], sze); [] [] x = new [10][20]; /* Jv code */ 3 4

Poers nd Arrys n C Recursve Dttypes n C [] = {1,2,3,4,5; * p = ; prf( %d\n, *p); prf( %d\n, *(p+2)); prf( %d\n, *(+2)); prf( %d\n, 2[]); /* ll of the bove pr 3 :-) */ [2] s shorthnd for *(+2); n ML: dttype ChrLst = EmptyChrLst ChrLstNode of chr * ChrLst; C requres tht ech dt type hs fxed mxmum sze determned t trnslton tme Ech node hs fxed sze nd they cn be strung together to form lst of rbtrry sze struct ChrLstNode { chr dt; struct ChrLstNode* next; ; typedef struct ChrLstNode* ChrLst; 5 6 Usng recursve poer types ChrLst cl = (ChrLst) mlloc(szeof(struct ChrLstNode)); (*cl).dt = ''; (*cl).next = 0; /* ths s so common tht there s short-hnd notton */ cl->dt = ''; cl->next = 0; (*cl).next = (ChrLst) mlloc(szeof(struct ChrLstNode)); (*(*cl).next).dt = 'b'; /* cl->next->dt='b'; */ (*(*cl).next).next = 0; /* cl->next->next=0; */ Type equvlence Structurl equvlence two dttypes re the sme f they hve the sme structure (trcker thn t sounds) Nme equvlence two types re the sme only f they hve the sme nme 7 8

C ML Type equvlence n C, ML nme equvlence for structs structure equvlence for everythng else type Age ; (structurl equvlence) dttype NewAge = NewAge ; (nme equvlence) Type checkng C, C++ : wek type checkng Scheme : strong dynmc type checkng Ad : strong type checkng no type nference (very verbose) ML : strong type checkng + type nference flexblty + protecton from errors 9 10 Polymorphc Type Checkng An exmple Hndley-Mlner type checkng (1969,1978) Mjor feture of ML nd Hskell The mchnery for utomtclly determnng the types of rguments nd results of functons wthout the progrmmer hvng to specfy them [] + + [] rry of Type checker flls n the types of ech node nd check f everythng s ok 11 12

An exmple Cn we do wthout type declrtons? [] + + [] Type checker flls n the types of ech node nd check f everythng s ok + type vrbles: + (only subscrpts) + rry of [] [] [] rry of rry of 13 14 Hndley-Mlner type checkng Instntton: once type vrble s replced by n ctul type, the ALL nstnces of tht vrble must be updted Unfcton: ny type vrble unfes wth ny type expresson type constnts unfy f they re the sme two type constructons unfy f they re the sme ll components lso (recursvely) unfy Unfcton exmples ' unfes to b' rry unfes to ' lst unfes wth 'b lst 2 cn not unfy wth rry of rry of cnnot unfy wth rry of chr 15 16

Polymorphc type checkng 'b rry must be the sme s ' rry therefore 'b nd ' re the sme but we don't know wht they re REALLY COOL Implct Prmetrc Polymorphsm (compler does t for you) Explct Prmetrc Polymorphsm Ad-hoc polymorphsm (overlodng) There s more to t Red pges 240-244 of your book nd usng your experence wth the ML compler you should hve no problem understndng them 17 18 Code trnslton for polymorphc types Wthout knowng the types trnsltor cnnot determne the sze of vlues Two solutons Expnson = exmne ll uses generte seperte code for ech use Boxng nd tggng = Fx sze for sclr types + sze feld for the rest (flg bt to dsmbgute) (lso used for grbge collecton) Explct Polymorphsm In ML (explct works ncely wth HM type checkng): dttype ' Stck = EmptyStck Stck of ' * (' Stck); In C++ (templtes re explct polymorphsm) Stck<> s; The most recent ddton to Jv re re Genercs whch re smlr. templte <typenme T> struct StckNode { T dt; StckNode<T> *next; ; templte <typenme T> struct Stck { StckNode<T>* thestck; ; 19 20