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

Slides:



Advertisements
Similar presentations
More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
Advertisements

Programming with Lists
The Stack Data Structure. Classic structure What is a Stack? An abstract data type in which accesses are made at only one end Last In First Out (LIFO)
For(int i = 1; i
1 OCAML §nucleo funzionale puro l funzioni (ricorsive) l tipi e pattern matching l primitive utili: liste l trascriviamo pezzi della semantica denotazionale.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e.
F28PL1 Programming Languages Lecture 14: Standard ML 4.
Chapter ElevenModern Programming Languages1 A Fourth Look At ML.
A Fourth Look At ML Chapter ElevenModern Programming Languages, 2nd ed.1.
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
1 OCAML - 2 §componente imperativo l variabili e assegnamento l primitive utili: arrays §moduli e oggetti.
5/11/2015IT 3271 Types in ML (Ch 11) datatype bool = true | false; datatype 'element list = nil | :: of 'element * 'element list n Predefined, but not.
Module Language. Module language The Standard ML module language comprises the mechanisms for structuring programs into separate units. –Program units.
25 September 2002BU CAS CS520 1 Parsing Combinators Hongwei Xi Boston University.
Stacks. COMP104 Slide 2 Stacks * A stack, S, is a data structure that supports: n push(x) make x the top element in stack S n Pop Remove the top item.
Introduction to ML – Part 1 Kenny Zhu. Assignment 2 chive/fall07/cos441/assignments/a2.ht m
Programming in the large in ML Need mechanisms for –Modularization –Information hiding –Parametrization of interfaces While retaining type inference Modules:
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
CSE 341 Lecture 6 exceptions; higher order functions; map, filter, reduce Ullman 5.2, 5.4 slides created by Marty Stepp
Modules in UHC A proposal by: Tom Hofte & Eric Eijkelenboom.
CS112 Intro to CS II with C++ Introduction. 6/25/2015Gene Itkis; cs1122 Problems and Programs Program helps articulate structure of Problem, and maybe.
Last Time Introduction Course Logistics Introduction to ML Base Types Tuples and Records Functions & Polymorphism See Harper ’ s Intro to ML.
Crash course on SML Wojciech Moczydłowski SML – functional programming language Complete formal semantics Extremely convenient for writing compilers, interpreters,
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Let A = {1,2,3,4} and B = {a,b,c}. Define the relation f from A to B by f = {(1,b), (2,a), (3,c), (4,b)}. Is f a function? (1) Yes (2) No.
Behavioral Pattern: Memento C h a p t e r 5 – P a g e 179 Objects frequently expose only some of their internal state using public methods, but there.
ML Introduction.1 Standard ML Introduction. ML Introduction.2 Includes: Most of the examples Most of the questions Most of the answers... Recommended.
F. Gava, HLPP 2005 Frédéric Gava A Modular Implementation of Parallel Data Structures in Bulk-Synchronous Parallel ML.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
CSE-321 Programming Languages Introduction to Functional Programming (Part II) POSTECH March 13, 2006 박성우.
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
ML modules Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 20, 2002.
Existential Types and Module Systems Xiaoheng Ji Department of Computing and Software March 19, 2004.
Programming LanguagesSection 41 Programming Languages Section 4. SML Remaining Topics Xiaojuan Cai Spring 2015.
Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming)
Functional Programming Language OCaml Tutorial 科大 - 耶鲁联合研究中心
Data Structures Stack Namiq Sultan 1. Data Structure Definition: Data structures is a study of different methods of organizing the data and possible operations.
CHAPTER 3 STACK CSEB324 DATA STRUCTURES & ALGORITHM.
CSE 332: C++ STL functors STL Functors: Functions vs. Function Objects STL Functors support function call syntax Algorithms invoke functions and operators.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 7, 2007 박성우.
Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library.
1/5/2016 Opener 1. (2m 3 – 4m 2 – 11) – (7m 3 – 3m 2 + 2m) 2. (4x + 2) (6x – 8) -5m 3 – m 2 – 2m – 11 24x 2 – 20x – 16.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Introduction to Functional Programming
Chapter TenModern Programming Languages1 Scope. Chapter TenModern Programming Languages2 Reusing Names Scope is trivial when all names are unique But.
Cs776(Prasad)L112Modules1 Modules value : type : function :: structure : signature : functor.
CSED101 INTRODUCTION TO COMPUTING FUNCTION ( 함수 ) 유환조 Hwanjo Yu.
1 Objective Caml (Ocaml) Aaron Bloomfield CS 415 Fall 2005.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH March 8, 2006 박성우.
CSE-321 Programming Languages Introduction to Functional Programming POSTECH 박성우.
Principles of programming languages 12: Functional programming
ML: a quasi-functional language with strong typing
Programming Languages Dan Grossman 2013
Tutorial 7.
slides created by Marty Stepp
52 Exponent Base 52 · 53 = 55 If the numerical bases are the same, keep the base and add the exponents.
Tim Sheard Oregon Graduate Institute
تعارف. تعارف قواعد العمل ا الموبيل المشروبات الاحاديث الجانبية الاسئلة نفكر.
CSE 341 Section 5 Winter 2018.
CSE-321 Programming Languages Introduction to Functional Programming
Warm-Up Add or subtract. 1) (5x2 + 4x + 2) + (-2x + 7 – 3x2)
Warm-Up 5 minutes Add or subtract. 1) (5x2 + 4x + 2) + (-2x + 7 – 3x2)
CSE-321 Programming Languages Introduction to Functional Programming
CSE-321 Programming Languages Introduction to Functional Programming
public class Dillo {     public int length;     public boolean isDead;         
Chapter Fourteen: Force and Motion
Warm-Up 5 minutes Add or subtract. 1) (5x2 + 4x + 2) + (-2x + 7 – 3x2)
Drew Wyborski Programming Languages
Presentation transcript:

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)

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

F-22 Standard ML/NJ

Rafale Ocaml

nML ?

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

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

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

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

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

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

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

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

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

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)