Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming)

Similar presentations


Presentation on theme: "Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming)"— Presentation transcript:

1 Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming) 값중심의 프로그래밍(values and applicative programming) 타입을 갖춘 프로그래밍(types and typeful programming) 모듈과 계층구조로 요약하기(modularity and hierarchy) 실행흐름의 관리(exceptions and advanced control) 맞는 프로그램인지 확인하기(program proof) Scheme ML

2 Typeful Programming 타입의 유용함, 겪어보았지요? – 프로그램을 짤 때 머리속을 정리해 주는. – 버그가 덜 생기게 해주는. “ type discipline ” = 타입중심 + 타입어긋나지 말자 신세계 = “ type discipline ” 을 강요하고, 타입 대로 잘 돌지 미리 자동으로 검증해 주는 시 스템

3 Technology for typeful programming automatic check for type-safety. the check is proven safe. types are infered( “ 인공지능 ” ). – no need for programmer ’ s comments about expression types polymorphic types – no need for separate copies of “ same ” functions for different types – let fun f(x) = x in (f 1, f “ a ” ) end

4 nML programming applicative programming value-oriented, not machine-oriented 값만 생각하는 프로그래밍 복잡한 머리는 터트려버려라

5 F-22 Standard ML/NJ

6 Rafale Ocaml

7 nML ?

8 대형 프로그래밍을 위한 기술들 supports for programming-in-the- large 모듈 = 정의들 + 박스포장 + 박스이름 –“ module ”, “.c file ”, “ structure ”, “ package ” 모듈 타입 = 박스안에 있는 정의들의 타입들 –“ interface ”, “.h file ”, “ signature ”, 일반화된 모듈 = 모듈을 인자로 받는 모듈 –“ generic package ”, “ class template ”, “ functor ” 타입 시스템 – 모듈 정의대로 외부에서 사용하는 지 자동으로 첵크 – 겉으로 드러내기로 한 내용만 사용하는 지 자동으로 첵크

9 Modules in nML val x = … type t=A|B … 이 보따리 이름은 Box structure Box = struct val x = … type t = … end Box.x … Box.A module(보따리)는 정의한(이름붙인) 것들을 하나로 모아놓고 이름붙여 놓은 것 입니다.

10 Modules in nML 그러한 보따리의 타입이 signature입니다. val x: int -> int type t val x: int -> int type t = A|B val x: int -> int signature S = sig … end signature matching structure XX: S = struct … end

11 functor(모듈함수)는 모듈을 받아서 모듈을 만드는 함수 functor F(X,Y) = struct … end function(함수)는 값을 받아서 값을 만드는 함수 fun f(x,y) = x+y Modules in nML functor F(X: sig … end, Y: sig … end) = struct … end functor F(X: S1, Y: S2) = struct … end

12 signature Animal = sig val age: int val think: string -> bool val feel: string -> bool end functor Couple(Beauty: Animal, Beast: Animal) = struct val age = Beauty.age + Beast.age fun think x = (Beauty.think x) orelse (Beast.think x) fun feel x = (Beauty.feel x) andalso (Beast.feel x) end

13 signature CAR = sig type speed type fuel val accelerator: int -> speed val break: int -> speed val fill_tank: int -> fuel end structure Porche = struct type speed = int type fuel = EMPTY | FULL of int fun accelerator n = n**n fun break n = n/10 fun fill_tank n = FULL n end

14 structure TicoDriver = DriverSchool(Tico) structure PorcheDriver = DriverSchool(Porche) functor DriverSchool(Car: CAR) = struct fun speed_up n = Car.accelerator n fun slow_down n = Car.break n fun get_ready n = Car.fill_tank n end signature CAR = sig type speed type fuel val accelerator: int -> speed val break: int -> speed val fill_tank: int -> fuel end

15 signature STACK = sig type atom type ‘a stack val empty_stack: atom stack val push: atom * atom stack -> atom stack end functor MakeStack(S: sig type t end) = struct type atom = S.t type ‘a stack = ‘a list val empty_stack = [] fun push (x, stk) = x::stk end

16 structure IntStk = MakeStack(struct type t = int end) structure StrStk = MakeStack(struct type t = string end) structure PairStk = MakeStack(struct type t = int * string end)


Download ppt "Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming)"

Similar presentations


Ads by Google