• Aucun résultat trouvé

J-O-Caml (4)

N/A
N/A
Protected

Academic year: 2022

Partager "J-O-Caml (4)"

Copied!
14
0
0

Texte intégral

(1)

J-O-Caml (4)

jean-jacques.levy@inria.fr

pauillac.inria.fr/~levy/qinghua/j-o-caml

Qinghua, November 27

(2)

Plan of this class

polymorphic mutable data

modules and signatures

manipulating terms as AST

reading bitmaps

ariane 5 story

(3)

Exercices

Conway sequences - solution 2

(4)

Polymorphism

variables and functions are polymorphic in Caml

type inference gives the principal type (unique most general)

no need to keep type information at runtime, since strong type checking differs from Lisp, Scheme, Java which keep and check type information

in Caml, polymorphism only appears around let statements

(5)

Polymorphic mutable data

mutable values can’t have real polymorphic types (see below)

they are not considered as real values only values have true polymorphic types

mutable values have ``once polymorphic’’ types

(6)

Modules and Signatures

module declaration groups related functions

qualified names to refer to functions and types

(7)

Modules and Signatures

implementation may be hidden by forcing signature

qualified names to refer to functions and types

(8)

Modules and Signatures

modules group set of type, exception, variable, function definitions

type of a module is its signature

signature can be restricted by giving it explicitly

hiding implementation of some types produce abstract types

several functions may also be hidden (usually auxiliary functions)

abstract types may have several implementations (FIFO as circular buffers, FIFO as lists)

if type is abstract, the user of this type will not see differences between implementations

signatures are described in the Ocaml libraries

compiled signatures are in files with suffix .cmi

modules may be nested

(9)

Exercice

Write remove function which removes the head of the queue in FIFO module (with creation of EmptyQueue exception)

Give a module definition for addition and multiplication for big numbers (as in exercice of lecture 2)

Give an alternative implementation of FIFOs with circular buffers.

(10)

Reading bitmaps

function to read bitmaps on standard input + 2 useful functions [format is: width(w) height(h) and h lines of w numbers]

(11)

Reading bitmaps

format is: nlines and ncolumns

(12)

Combien d’objets dans une image?

Jean- Jacques L évy

INRIA

(13)

Labeling

16 objects in this picture 1

1

2 3

4 5 6

7

8 9

10

11 12

13 14

(14)

Algorithm

1) first pass

-

scan pixels left-to-right, top-to-bottom giving a new object id each time a new object is met

2) second pass

-

generate equivalences between ids due to new adjacent relations met during scan of pixels.

3) third pass

-

compute the number of equivalence classes

Complexity:

-

scan twice full image (linear cost)

-

try to efficiently manage equivalence classes (Union-Find by Tarjan)

Références

Documents relatifs

4 Develop original methods of conveying and promoting African values by drawing inspiration from traditional socialization approaches, such as initiation ceremonies

Active mode is when you want to transfer data you have to tell the server the address and port to connect to. Passive mode is when the server provide the address and port and

• Assessment of the costs and benefits of feasible measures to achieve groundwater threshold values and their distribution across different interest groups in society7. •

Building upon ideas of the second and third authors, we prove that at least 2 (1−ε)(log s)/(log log s) values of the Riemann zeta function at odd integers between 3 and s

[r]

As many family physicians come limping out of this pandemic, this is the time to celebrate the many, many ways in which family physicians have absorbed a huge amount of

Some immi- grant women, less proficient in oral than in writ- ten English, indicated they wanted a self-report version they could complete and return to their health

In conjunction with Israeli psychologist Jeremy Ginges and Palestinian political scientist Khalil Shikaki, our team surveyed more than twelve hundred Palestinians in the West Bank