1 OCAML - 2 §componente imperativo l variabili e assegnamento l primitive utili: arrays §moduli e oggetti.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
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.
Stack & Queues COP 3502.
Sit-in lab 4.  Given a number of strings containing only “a”, “b”, “c”, “d”  Check each string that it follows the pattern a n b m c m d n where m,
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
1 OCAML nucleo funzionale puro – funzioni (ricorsive) – tipi e pattern matching – trascriviamo pezzi della semantica operazionale – primitive utili: liste.
Implementing Stacks Using Arrays CSC 1401: Introduction to Programming with Java Week 14 – Lecture 1 Wanda M. Kunkle.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
 2006 Pearson Education, Inc. All rights reserved Generics.
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Call Stacks John Keyser. Stacks A very basic data structure. – Data structure: a container for holding data in a program. – Classes, structs can be thought.
08 1 Abstract Data Types Problem Sets: PS2 due due Monday, Feburary 26 PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 08 Monday, February 26.
Chapter 3 Introduction to Collections – Stacks Modified
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.
References types and Value types With a very brief introduction to struct and enum Reference types and Value types1.
Review & Preview 재귀와 반복(recursion and iteration) 함수로 요약하기(procedural abstraction) 데이터로 요약하기(data abstraction) 물건중심의 프로그래밍(objects and imperative programming)
Cs776 (Prasad)L16rem1 Remaining Features of SML97 Records Exceptions Reference Types Arrays.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
Духовні символи Голосіївського району
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
Stack Data Structure By Marwa M. A. Elfattah. Stack - What A stack is one of the most important non- primitive linear data structure in computer science.
NML programming applicative programming value-oriented, not machine-oriented 값만 생각하는 프로그래밍 복잡한 머리는 터트려버려라.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
CMSC 330: Organization of Programming Languages Object Oriented Programming with OCaml.
Popping Items Off a Stack Using a Function Lesson xx
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Stacks A stack is a data structure that is similar in spirit to a pile of cafeteria trays. Think about the trays in the dining halls: when the dining staff.
Stack Memory 1 (also called Call Stack)
Objective caml Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 18, 2002.
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Stacks and Queues Prof. Michael Tsai 2017/02/21.
UNIT-II.
Presentation transcript:

1 OCAML - 2 §componente imperativo l variabili e assegnamento l primitive utili: arrays §moduli e oggetti

2 Variabili e frammento imperativo # let x = ref(3);; val x : int ref = {contents=3} # !x;; - : int = 3 # x := 25;; - : unit = () # !x;; - : int = 25 # x := !x + 2; !x;; - : int = 27

3 Un tipo primitivo mutabile: l’array # let a = [| 1; 2; 3 |];; val a : int array = [|1; 2; 3|] # let b = Array.make 12 1;; val b : int array = [|1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1|] # Array.length b;; - : int = 12 # Array.get a 0;; - : int = 1 # Array.get b 12;; Uncaught exception: Invalid_argument("Array.get") # Array.set b 3 131;; - : unit = () # b;; - : int array = [|1; 1; 1; 131; 1; 1; 1; 1; 1; 1; 1; 1|]

4 Moduli: interfaccie # module type PILA = sig type 'a stack (* abstract *) val emptystack : 'a stack val push : 'a stack -> 'a -> 'a stack val pop : 'a stack -> 'a stack val top : 'a stack -> 'a end;; module type PILA = sig type 'a stack val emptystack : 'a stack val push : 'a stack -> 'a -> 'a stack val pop : 'a stack -> 'a stack val top : 'a stack -> 'a end

5 Moduli: implementazione # module SpecPila: PILA = struct type 'a stack = Empty | Push of 'a stack * 'a let emptystack = Empty let push p a = Push(p,a) let pop p = match p with | Push(p1, _) -> p1 let top p = match p with | Push(_, a) -> a end;; module SpecPila : PILA

6 Classi e oggetti # class point x_init = object val mutable x = x_init method get_x = x method move d = x <- x + d end;; class point : int -> object val mutable x : int method get_x : int method move : int -> unit end # let p = new point (3);; val p : point = # p#get_x;; - : int = 3 # p#move 33;; - : unit = () # p#get_x;; - : int = 36

7 Ereditarietà class point : int -> object val mutable x : int method get_x : int method move : int -> unit end # class colored_point x (c : string) = object inherit point x val c = c method color = c end;; class colored_point : int -> string -> object val c : string val mutable x : int method color : string method get_x : int method move : int -> unit end # let p' = new colored_point 5 "red";; val p' : colored_point = # p'#color;; - : string = "red"

8 Il linguaggio didattico §le cose semanticamente importanti di OCAML, meno l tipi (e pattern matching) l moduli l eccezioni