Review & Preview
E N D
Presentation Transcript
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
Typeful Programming • 타입의 유용함, 겪어보았지요? • 프로그램을 짤 때 머리속을 정리해 주는. • 버그가 덜 생기게 해주는. • “type discipline” = 타입중심 + 타입어긋나지말자 • 신세계 = “type discipline”을 강요하고, 타입대로 잘 돌지 미리 자동으로 검증해 주는 시스템
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
ML programming applicative programming value-oriented, not machine-oriented 값만 생각하는 프로그래밍 복잡한 머리는 터트려버려라
대형 프로그래밍을 위한 기술들supports for programming-in-the-large • 모듈 = 정의들 + 박스포장 + 박스이름 • “module”, “.c file”, “structure”, “package” • 모듈 타입 = 박스안에 있는 정의들의 타입들 • “interface”, “.h file”, “module type”, “signature” • 일반화된 모듈 = 모듈을 인자로 받는 모듈 • “generic package”, “class template”, “functor”, “parameterized module” • 타입 시스템 • 모듈 정의대로 외부에서 사용하는 지 자동으로 첵크 • 겉으로 드러내기로 한 내용만 사용하는 지 자동으로 첵크
Modules in ML 이 보따리 이름은 Box val x = … type t=A|B … module Box = struct val x = … type t = … end Box.x … Box.A module(보따리)는 정의한(이름붙인) 것들을 하나로 모아놓고 이름붙여 놓은 것 입니다.
Modules in ML 그러한 보따리의 타입: module type S = sig … end val x: int -> int type t signature matching val x: int -> int type t = A|B module XX: S = struct … end val x: int -> int
Modules in ML function(함수)는 값을 받아서 값을 만드는 함수 fun f(x,y) = x+y functor(모듈함수)는 모듈을 받아서 모듈을 만드는 함수 functor F(X,Y) = struct … end module F (X: sig … end, Y: sig … end) = struct … end module F (X: S1, Y: S2) = struct … end
module type Animal= sig val age: int val think: string -> bool val feel: string -> bool end moduleCouple (Beauty: Animal, Beast: Animal) = struct valage = Beauty.age+ Beast.age letthinkx = (Beauty.thinkx) || (Beast.thinkx) letfeelx = (Beauty.feelx) && (Beast.feelx) end
module type CAR = sig type speed type fuel val accelerator: int -> speed val break: int -> speed val fill_tank: int -> fuel end module Porche = struct type speed = int type fuel = EMPTY | FULL of int let accelerator n = n**n let break n = n/10 let fill_tank n = FULL n end
module type CAR = sig type speed type fuel val accelerator: int -> speed val break: int -> speed val fill_tank: int -> fuel end module DriverSchool(Car: CAR) = struct let speed_up n = Car.accelerator n let slow_down n = Car.break n let get_ready n = Car.fill_tank n end module TicoDriver = DriverSchool(Tico) module PorcheDriver = DriverSchool(Porche)
module type STACK = sig type atom type ‘a stack val empty_stack: atom stack val push: atom * atom stack -> atom stack end module MakeStack(S: sig type t end) = struct type atom = S.t type ‘a stack = ‘a list let empty_stack = [] let push (x, stk) = x::stk end
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)