nml programming n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
nML programming PowerPoint Presentation
Download Presentation
nML programming

Loading in 2 Seconds...

play fullscreen
1 / 16

nML programming - PowerPoint PPT Presentation


  • 74 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'nML programming' - doris-briggs


Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
nml programming
nML programming

applicative programming

value-oriented, not machine-oriented

값만 생각하는 프로그래밍

복잡한 머리는 터트려버려라

what is applicative programming
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)

slide3

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

slide7

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])

slide8

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

slide9

Modules in nML

이 보따리 이름은 Box

val x = …

type t=A|B

structure Box =

struct

val x = …

type t = …

end

Box.x … Box.A

module(보따리)는 정의한(이름붙인) 것들을 하나로

모아놓고 이름붙여 놓은 것 입니다.

slide10

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

slide11

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

slide12

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

slide13

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

slide14

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)

slide15

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

slide16

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)