Signature, Strong Typing

Slides:



Advertisements
Similar presentations
Copyright © 2015 Pearson Education, Inc. 6 장 : 프로그래밍 언어.
Advertisements

YES C 제 1 장 C 언어의 개요 1/34 제 1 장 C 언어의 개요 문봉근. YES C 제 1 장 C 언어의 개요 2/34 제 1 장 C 언어의 개요 1.1 프로그램과 C 언어의 특징 1.2 C 언어의 프로그램 구성 1.3 비주얼 C++ 통합 환경 들어가기.
Copyright © 2006 The McGraw-Hill Companies, Inc. 프로그래밍 언어론 2nd edition Tucker and Noonan 5 장 타입 “ 타입은 컴퓨터 프로그래밍의 효소이다 ; 프로그래밍은 타입을 통해 소화할만한 것이 된다.” 로빈.
제 4 장 변수, 영역, 수명 변수 바인딩 영역 기억장소 할당과 수명 변수와 그 환경 변수 초기화 상수와 변수.
3. C++와 객체지향 C++ 코딩 방법 객체 단위로 2 개의 파일 인터페이스 파일 구현파일
Programming Languages Type Conversion Classifying Type Conversions According to the notation –Implicit Conversions (coercion) –Explicit Conversions (casting)
제 3장 프로그래밍 언어 설계 3.1 설계 기준의 역사적 변천 3.2 효율성 3.3 일반성, 직교성, 획일성
Chapter 3 – 프로그래밍 언어 설계 Outline 3.1 설계 기준의 역사적 변천 3.2 효율성
Chapter 10 – 추상 자료형 Outline 10.1 소개 10.2 Ada의 추상 자료형 10.3 C++의 추상 자료형
제 12장 예외 처리 12.1 설계 쟁점 12.2 PL/I의 ON-조건 12.3 Ada의 예외 처리
데이터 구조 - 소개 순천향대학교 컴퓨터공학과 하 상 호.
알고리즘(Algorithm)  알고리즘 개요 (효율, 분석, 차수) Part 1 강원대학교 컴퓨터과학전공 문양세.
Delphi 2009의 언어 개선 박지훈.임프 2018년 11월 16일 금요일
Chapter 11 – 예외 처리 Outline 11.1 설계 쟁점 11.2 Pl/I의 예외 처리 11.3 Ada의 예외 처리
10장 예외 처리 프로그래밍 언어론 10.6 Pascal과 C의 에러 처리 10.1 설계 주제 10.2 PL/I의 예외 처리
윤 홍 란 제3장 클래스와 객체의 사용-1 윤 홍 란
제 6 장 데이터 타입 6.1 데이터 타입 및 타입 정보 6.2 타입의 용도 6.3 타입 구성자 6.4 사례 연구
프로그래밍 언어론 2004년 가을학기 창 병 모 숙명여대 컴퓨터과학과.
Ruby 프로그래밍 1 문자열 입출력 제어구조 looping 함수 정의
Internet Computing KUT Youn-Hee Han
2주 실습강의 Java의 기본문법(1) 인공지능연구실.
12. 데이터베이스 설계.
Java RMI (Remote Method Invocation)
10장 객체-지향 프로그래밍 II ©창병모.
바인딩, 메모리 관리 SANGJI University Kwangman Ko
Part 08 함수 ©우균, 창병모 이 슬라이드는 부산대학교 우균이 작성하였습니다. 오류나 수정할 사항 있으면 연락 주세요.
Chapter 6 – 변수, 바인딩, 식 및 제어문 Outline 6.1 변수 6.2 바인딩 6.3 선언 6.4 배정문
Chapter 9 – 부 프로그램 Outline 9.1 개요 9.2 매개변수 평가와 전달기법 9.3 형식 매개변수 명세
Ch2-2. VHDL Basic VHDL lexical element VHDL description
[INA240] Data Structures and Practice
3장. 포인터, 배열, 구조체 포인터, 배열, 구조체 학습목표 기본적 데이터 타입
윤 홍 란 4 장 클래스 작성 윤 홍 란
제 2 장 변수와 상수.
Derived Types-- Enumerated, Structure and Union
5장 이름, 바인딩, 영역(2) 순천향대학교 컴퓨터공학과 하상호.
제 10장 부 프로그램 10.1 개요 10.2 매개 변수 평가와 전달 기법 10.3 형식 매개 변수 명세
프로그래밍 보고서 작성법 순천향대학교 컴퓨터공학과 하 상 호.
기초 프로그래밍 Yang-Sae Moon Department of Computer Science
메소드와 클래스 정의 및 문제 풀이 Method and Class Define and Problem Solve
운영체제 (Operating Systems) (Memory Management Strategies)
Introduction to Programming Language
알고리즘(Algorithm)  알고리즘 개요 (효율, 분석, 차수) Part 년 봄학기
6장 데이터 타입(2) 순천향대학교 컴퓨터공학부 하 상 호.
[CPA340] Algorithms and Practice Youn-Hee Han
Signature, Strong Typing
[INA470] Java Programming Youn-Hee Han
컴퓨터공학실습(I) 3주 인공지능연구실.
제 5장 변수, 바인딩, 식 및 제어문 5.1 변수 5.6 표현식 5.2 바인딩 5.7 조건문 5.3 선언 5.8 반복문
제 1 장. 자료구조와 알고리즘.
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
Chapter 4 변수 및 바인딩.
Chapter 02. 소프트웨어와 자료구조.
Signature, Strong Typing
데이터 구조 - 소개 순천향대학교 컴퓨터공학과 하 상 호.
Chapter 13 – 객체 지향 프로그래밍 Outline 13.1 소프트웨어의 재사용과 독립성
자바 5.0 프로그래밍.
Signature, Strong Typing
Java RMI (Remote Method Invocation)
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
창 병 모 숙명여대 전산학과 자바 언어를 위한 CFA 창 병 모 숙명여대 전산학과
Chapter 3 – 프로그래밍 언어 설계 Outline 3.1 설계 기준의 역사적 변천 3.2 효율성
첫 번째 수치 문제 컴퓨터시뮬레이션학과 담당교수 : 이형원 E304호,
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
캡슐화 (Encapsulation) 두원공과대학 소프트웨어개발과 이 원 주.
Signature, Strong Typing
Programming Language Technology Trends
기업경영과 생산관리 교재 : 강의 홈 김태웅 지음, 생산, 운영관리의 이해 (제3판), 신영사
Signature, Strong Typing
제 1장 프로그래밍 언어 소개 1.1 프로그래밍 언어란 무엇인가 1.2 프로그래밍 언어를 배워야 하는 이유
Scalar and composite data
Presentation transcript:

Signature, Strong Typing

Signature I Specification of an operation, the number, order and types of the arguments in the domain of an operation + : integer x integer  integer = : integer x integer  Boolean SQRT : real  real op name : arg type x arg type x … arg type  result type Function prototype (C)

Signature II Situations that make difficult specifying an operation as a mathematical function Operations that are undefined for certain inputs Square-root, overflow나 underflow를 초래하는 연산 Implicit arguments Global variables, non-local identifier reference Side effect An operation may return an explicit result, but it also modify the values stored in other objects, both programmer- and system-defined … modification of input arguments Self-modification (history sensitivity) modify its own internal structure, either local data that are retained between executions or its code… random number generator .. Java, LISP …. Java에서 어떻게???? --- static type

Declarations float A, B; $abc = ‘a string’; $abc = 7; imax =7 DECLARE X FIXED DECIMAL (5,3)

Purposes for Declarations Choice of storage representation Storage management Lifetimes of data objects  memory class of C, C++ Polymorphic operations Resolving overload (generic) at compile time Type checking

Type checking Type error Runtime (dynamic type) checking  Compile time (static type) checking Dynamic type checking, typeless  flexibility in program design (polymorphism) Disadvantage Difficult to debug Type information must be kept during program execution Slowdown the execution speed

Information for Static type checking For each operation, the number, order, and data types of its arguments and results (i.e signature) The type of data object associated with a variable must be invariant … For each variable, the type of data object named The type of each constant data object

Static type checking …. In most languages, static type checking is not possible By dynamic type checking … high cost By leaving the operations unchecked …cause serious and subtle program errors

Strong Typing 컴파일 과정에서 모든 형 검증이 끝나는 (static type checking) 언어를strongly typed언어라고 한다. Algol 68은 strongly typed 언어이지만, PASCAL은 아니다.

Pascal ⒜ PASCAL에서 프로시듀어나 함수가 인자로 사용될 경우 번역 과정에서 형 검증을 할 수 없다. 경우 번역 과정에서 형 검증을 할 수 없다. precedure who_knows( i, j : integer; procedure f ); var k : boolean; begin k := j < i; if k then f(k) else f(i) end 위의 프로그램에서 컴파일러는 f(k)와 f(i)가 오류인지 아닌지 알 수 없다. 그 이유는 실질 인자(actual parameter)가 무엇인지에 따라 오류 여부가 결정되기 때문이다.

Algol Algol 68은 그와 같은 문제가 발생하지 않는다. proc who_knows = ( int i, int j, proc(bool) void f) void : begin bool k; k := j < i; if k then f(k) else f(j) error !!! fi end  C언어는?

다른 비교 Algol68에서는 위의 문제를 type이 맞지 않는 것으로 보지 않고, value가 맞지 않는 것으로 취급한다. (B) PASCAL에서 a, b, c가 1..10인 subrange 형일 경우에, "a := b + c"가 오류일지 아닐 지는 수행 시에만 알 수 있다 Algol68에서는 위의 문제를 type이 맞지 않는 것으로 보지 않고, value가 맞지 않는 것으로 취급한다.

다른 비교 ⒞ ⒟ PASCAL의 variant record는 번역시에 검증 못함 Algol 68의 union은 그렇지 않다. 수행 시 검증이 필요한 것은 프로그래머가 명시적으로 프로그램해야 한다. ⒟ PASCAL에서는 형 일치(type-compatibility)에 대한 규칙이 없지만, Algol 68은 명확히 정의되어 있다.

형 일치 이름 일치(Name equivalence) 구조적 일치(Structural equivalence) 두 변수의 형은 동일한 사용자 정의나 내장형 이름일 경우, 또는 같은 선언에 나타난 경우에만 일치한다. 따라서 d, e.b와 f.b는 같은 형이고, a와 b는 같은 형이며, e와 f 같은 형이다. 그러나 a와 c는 같은 형이 아니다. 구조적 일치(Structural equivalence) 두 변수는 같은 구조를 가지면 같은 형이다. 이 경우 a, b, c, d, e.b와 f.b는 같은 형이다.

실제 예 Algol 68은 구조적 일치 기법으로 형 일치를 검증하도록 정의되어 있다. PASCAL은 컴파일러 구현과정에서 정의되도록 되어있다. 따라서 같은 PASCAL 프로그램도 컴파일러에 따라 결과가 다를 수 있다. 대부분의 PASCAL 컴파일러는 구조적 일치를 사용하지만, 인자 교환(parameter passing)에서는 이름일치를 사용한다. 이름일치를 사용할 경우 정수 값을 정수의 subrange형인 변수에 형 변환(type conversion) 없이는 기억시킬(assign) 수 없다.

형 일치(Type compatibility) 프로그램의 예 type t = array[1..20] of integer; var a, b : array[1..20] of integer; c : array[1..20] of integer; d : t e, f : record a : integer; b : t end

숙제 pointer를 잘못 사용하면 생길 수 있는 오류와 이를 해결하는 각 프로그래밍 언어가 취하는 방법을 설명하라!!! PL 자습자료를 참고하면 됨 !!!!! C 언어에서 compile time에 type checking이 불가능한 예를 보여라.