1 / 16

nML programming

nML programming. applicative programming. value-oriented, not machine-oriented. 값만 생각하는 프로그래밍. 복잡한 머리는 터트려버려라. What is applicative programming?. VALUES ARE IMMUTABLE. 1, 2, 3, 1+2, {kwang, young}U{sang}. OBJECTS ARE CHANGING. 1, 2, 3, 1.add2, {kwang, young}.add(sang). S. S. 1, 2, 3, 4.

Download Presentation

nML programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. What is applicative programming? VALUES ARE IMMUTABLE. 1, 2, 3, 1+2, {kwang, young}U{sang} OBJECTS ARE CHANGING. 1, 2, 3, 1.add2, {kwang, young}.add(sang)

  3. S S 1, 2, 3, 4 1, 2, 3 S.add(4) T = add(S,4) T 1, 2, 3 1, 2, 3 4 S S

  4. F-22 Standard ML/NJ

  5. Rafale Ocaml

  6. nML ?

  7. Homework 2-1 ([],[]) fun insert(x,l) = x::l fun delete(x::[]) = x | delete(x::r) = delete r | delete [] = raise ... fun delete(x::r) = x | delete [] = raise ... ([1],[]) ([2,1],[]) ([3,2,1],[]) ([],[1,2,3]) ([], [2,3]) ([4], [2,3]) ([4],[3]) ([9,4],[3])

  8. Homework 2-2 type val = type env = type mem = fun eval(SEQ(e1,e2),env,mem) = let val (v1,mem1) = eval(e1,env,mem) val (v2,mem2) = eval(e2,env,mem1) in (v2,mem2) end

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

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

  11. Modules in nML function(함수)는 값을 받아서 값을 만드는 함수 fun f(x,y) = x+y functor(모듈함수)는 모듈을 받아서 모듈을 만드는 함수 functor F(X,Y) = struct … end 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. signature CAR = sig type speed type fuel val accelerator: int -> speed val break: int -> speed val fill_tank: int -> fuel end 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 structure TicoDriver = DriverSchool(Tico) structure PorcheDriver = DriverSchool(Porche)

  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)

More Related