J-O-Caml (1) Qinghua, November 19.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
CMSC 330: Organization of Programming Languages Tuples, Types, Conditionals and Recursion or “How many different OCaml topics can we cover in a single.
Writing functions in OCaml. Defining a simple function # let add (x, y) = x + y;; val add : int * int -> int = Notice what this says: –add is a value.
Programming Languages and Paradigms The C Programming Language.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
A Fourth Look At ML Chapter ElevenModern Programming Languages, 2nd ed.1.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Getting Started with Haskell Tim Sheard. Learning a new language Goals – Learn how to design and use data structures – Learn to write programs using the.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Functional Programming Language (Introduction and Scheme) Lecture 17 – Functional Programming, Spring.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Mark Hennessy Dept. Computer Science NUI Maynooth 1 CaML continued CS 351 Programming Paradigms Dept. Computer Science NUI Maynooth.
Starting out with C++1 Chapter 9 – Pointers Getting the address of a Variable Why do we have pointers? Indirection – difference between –Will you go out.
Programming 1 Tim Sheard. Spring Quarter Goals of the class – Learn to write simple programs using the programming language Haskell. – Learn by example.
C++ Training Datascope Lawrence D’Antonio Lecture 1 Quiz 1.
0 PROGRAMMING IN HASKELL Chapter 3 - Types and Classes.
Recursion & Collections API Recursion Revisited Programming Assignments using the Collections API.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
CS235 Languages and Automata Department of Computer Science Wellesley College Introduction to Standard ML Wednesday, September 23, 2009 Reading: Beginning.
Computer programming Lecture 5. Lecture 5: Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character arrays.
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.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
J-O-Caml (6) pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4.
J-O-Caml (2) pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, November 20.
What is a Type? A type is a name for a collection of related values. For example, in Haskell the basic type Bool contains the two logical values: True.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
J-O-Caml (3) pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, November 26.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
CMSC 330: Organization of Programming Languages
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
CSED101 INTRODUCTION TO COMPUTING FUNCTION ( 함수 ) 유환조 Hwanjo Yu.
Data in Haskell. What is data? Measurements of some kind stored in a computer. – Examples Simple: numbers, text, truth values … Structured: sequences,
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Hindley-Milner Type Inference CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
Recursion in Java The answer to life’s greatest mysteries are on the last slide.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
1 Objective Caml (Ocaml) Aaron Bloomfield CS 415 Fall 2005.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
A Sample Program #include using namespace std; int main(void) { cout
Object Oriented Programming Lecture 2: BallWorld.
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Functional Programming
Lecture 24: Recursion Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson All rights reserved.
Principles of programming languages 12: Functional programming
Programming Languages
dr Robert Kowalczyk WMiI UŁ
PROGRAMMING IN HASKELL
Types CSCE 314 Spring 2016.
Semantic Analysis Type Checking
CSE 303 Lecture 9 C programming: types, functions, and arrays
Week 4 - Friday CS221.
A lightening tour in 45 minutes
Programming fundamentals 2 Chapter 1:Array
Programming Languages
Data type List Definition:
CSE-321 Programming Languages Introduction to Functional Programming
Haskell Types, Classes, and Functions, Currying, and Polymorphism
PROGRAMMING IN HASKELL
Lecture 19: Recursion Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson All rights reserved.
PROGRAMMING IN HASKELL
Variables and Computer Memory
PROGRAMMING IN HASKELL
Presentation transcript:

J-O-Caml (1) Qinghua, November 19

Plan of this class writing programs in Ocaml functional programming use of polymorphic types pattern-matching tour in the libraries

Functional programming Scheme, SML, Ocaml, Haskell are functional programming languages they manipulate functions and try to reduce memory states Lisp Scheme ML HaskellOcaml Caml Camllight Ocaml JocamlSML

Installing Ocaml google Ocaml caml.inria.fr/index.en.html download the system (Linux, MacOS, Windows) results in:  ocaml (interactive toplevel)  ocamlc (compiler)

Phrases at toplevel

Scopes of definitions let, let in, let and, let and in, let rec, let rec in... fine control in definition scopes

Scopes of definitions let, let in, let and, let and in, let rec, let rec in... fine control in definition scopes

Scopes of definitions fine control in definition scopes

Scopes of definitions fine control in definition scopes

Basic types int (integers) 1, 2, 3,... float (real numbers) 2.3, 1.2, 0. char (characters) ‘a’, ‘b’, ‘c’,... bool (booleans) true, false unit (void) () Compound built-in types string (strings) “nihao”,... list (lists of any type) [1; 2], 3 :: [4; 6] array (arrays of any type) [| 1; 2; 3; 4 |]

No overloading in Ocaml (on integers) (on real numbers) (not allowed) (float_of_int 3) (legal expression) this is to ease type inference Operations on compound types “nihao”.[3] (character at position) List.hd [1; 2], List.tl [1; 2] (head and tail of list) [| 1; 2; 3; 4 |].(3) (element at some index in array)

Small examples on arrays

Easy exercices isPalindromic s returns true if s is palindrome reverse s returns mirror image of s (Use s.[i] <- c store character c at ( i + 1) position in s)

More exercices sort a sorts array a in place (Use a.(i) <- x store x at ( i + 1) position in a ) transpose a transposes matrix a in place (Use a.(i).(j) <- x store x at ( i + 1), ( j + 1) position in a ) (also Array.make_matrix h w v creates h x w matrix filled with value v )

Objective for next classes a labeling algorithm for bitmap graphics

Combien d’objets dans une image? Jean-Jacques Lévy INRIA

pixels Mpix 10 6 (pictures elements)

Problem and Algorithm

What is an object? set of similar adjacent pixels - similar ? simplification - grayscale images (255 values) - 0 = black, 255 = white - similar = adjacent with close values give a disctinct number to each object number of objects is max of previous numbers

Labeling 15 objects in this picture

Exercise for next class find an algorithm for the labeling algorithm