Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LIFPF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FERCHICHE FARES p2208151
LIFPF
Commits
ddf57466
Commit
ddf57466
authored
2 years ago
by
COQUERY EMMANUEL
Browse files
Options
Downloads
Patches
Plain Diff
CM2
parent
e5251bd5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
cm/cm2-demo.md
+244
-0
244 additions, 0 deletions
cm/cm2-demo.md
cm/lifpf-cm2.pdf
+0
-0
0 additions, 0 deletions
cm/lifpf-cm2.pdf
with
245 additions
and
1 deletion
README.md
+
1
−
1
View file @
ddf57466
...
...
@@ -6,7 +6,7 @@
| ----- | ------------- | ---- | -------------------------------------------------------------------- |
| 16/01 | 8h | CM |
[
Diapositives
](
cm/lifpf-cm1.pdf
)
|
| | 9h45 | TD |
[
Sujet
](
td/lifpf-td1-enonce.pdf
)
<br>
Groupes B et E à 11h30 |
| 23/01 | 8h | CM | Diapositives
à venir
|
| 23/01 | 8h | CM |
[
Diapositives
](
cm/lifpf-cm2.pdf
)
,
[
Script démos
](
cm/cm2-demo.md
)
|
| | 9h45 ou 11h30 | TP |
[
Sujet
](
tp/tp1.md
)
<br>
Groupe de TP, horaire et salle sur [tomuss] |
[
tomuss
]:
https://tomuss.univ-lyon1.fr
This diff is collapsed.
Click to expand it.
cm/cm2-demo.md
0 → 100644
+
244
−
0
View file @
ddf57466
## Variables
```
ocaml
let
x_g
=
3
;;
let
x
=
2
in
3
+
x
*
x
;;
let
x
=
5
in
let
y
=
x
+
2
in
x
*
y
;;
let
x
=
let
y
=
3
in
y
*
y
in
x
+
10
;;
```
## Appels de fonction
```
ocaml
not
false
;;
log
10
.
0
;;
abs
(
int_of_string
"-3"
);;
hypot
3
.
0
4
.
0
;;
hypot
(
2
.
5
+.
0
.
5
)
(
2
.
0
*.
2
.
0
);;
hypot
2
.
0
1
.
5
*.
2
.
0
;;
hypot
2
.
0
(
1
.
5
*.
2
.
0
)
;;
```
## Définitions de fonction
```
ocaml
let
carre
(
x
:
int
)
:
int
=
x
*
x
;;
let
carre2
x
=
x
*
x
;;
let
cube
x
=
x
*
x
*
x
in
cube
2
;;
let
cube
(
x
:
int
)
:
int
=
let
carre3
y
=
y
*
y
in
carre3
x
*
x
;;
cube
4
;;
carre3
;;
```
## Énumérations
```
ocaml
type
jour
=
|
Lundi
|
Mardi
|
Mercredi
|
Jeudi
|
Vendredi
|
Samedi
|
Dimanche
;;
Lundi
;;
Mercredi
;;
Lundi
=
Mercredi
;;
Lundi
<
Mercredi
;;
```
## Filtrage
```
ocaml
match
Lundi
with
|
Mardi
->
2
|
Mercredi
->
3
|
Lundi
->
1
|
Vendredi
->
5
|
Dimanche
->
7
|
Samedi
->
6
|
Jeudi
->
4
;;
match
Lundi
with
|
Mardi
->
2
|
Mercredi
->
3
|
Lundi
->
1
|
Vendredi
->
5
|
Dimanche
->
7
|
Samedi
->
6
(* | Jeudi -> 4 *)
;;
let
weekend
(
j
:
jour
)
:
bool
=
match
j
with
|
Samedi
->
true
|
Dimanche
->
true
|
autre
->
false
;;
let
weekend
(
j
:
jour
)
:
bool
=
match
j
with
|
Samedi
->
true
|
Dimanche
->
true
|
_
->
false
;;
```
## Nuplet
```
ocaml
match
(
3
.
5
,
"coucou"
)
with
|
(
_
,
s
)
->
s
^
" tout le monde"
;;
```
## Filtrage sur types de base
```
ocaml
let
is_zero
(
n
:
int
)
:
bool
=
match
n
with
|
0
->
true
|
_
->
false
;;
is_zero
1
;;
is_zero
0
;;
```
## Types sommes avec données
```
ocaml
type
nombre
=
|
Int
of
int
|
Float
of
float
|
Cplx
of
float
*
float
|
Nan
;;
Int
3
;;
Cplx
(
3
.
0
,
7
.
2
);;
let
int_of_nombre
(
n
:
nombre
)
:
int
=
match
n
with
|
Int
i
->
i
|
Float
f
->
int_of_float
f
|
Cplx
(
r
,_
)
->
int_of_float
r
|
Nan
->
0
;;
int_of_nombre
(
Cplx
(
3
.
0
,
7
.
2
));;
```
## Pattern matching en profondeur
```
ocaml
let
is_zero
(
n
:
nombre
)
:
bool
=
match
n
with
|
Int
0
->
true
|
Float
0
.
0
->
true
|
Cplx
(
0
.
0
,
0
.
0
)
->
true
|
_
->
false
;;
```
## Rappel récursivité
```
ocaml
(**
Fonction qui calcule la somme des carrés des n premiers entiers
@param n le nombre d'entiers
@return la somme
*)
let
rec
somme_carres
(
n
:
int
)
:
int
=
if
n
<=
0
then
0
else
n
*
n
+
somme_carres
(
n
-
1
);;
```
## Listes
```
ocaml
let
l1
=
1
::
3
::
5
::
[]
;;
let
l2
=
[
1
;
3
;
5
];;
l1
=
l2
;;
type
resultat
=
Aucun
|
Int
of
int
;;
(**
Cette fonction donne le maximum d'un liste d'int
@param l la liste dont on veut le max
@return le max ou Aucun si la liste est vide
*)
let
rec
maximum
(
l
:
int
list
)
:
resultat
=
match
l
with
|
[]
->
Aucun
|
x
::
[]
->
Int
x
|
x
::
l2
->
match
maximum
l2
with
|
Aucun
->
Int
x
|
Int
y
->
if
x
>
y
then
Int
x
else
Int
y
;;
maximum
[
2
;
1
;
5
;
3
];;
maximum
[
2
];;
maximum
[]
;;
(**
Calcule le maximum dans une liste de liste d'int
@param ll la liste de liste
@return le max ou Aucun s'il n'y a pas d'int dans ll
*)
let
rec
maximum2
(
ll
:
int
list
list
)
:
resultat
=
match
ll
with
|
[]
->
Aucun
|
l
::
[]
->
maximum
l
|
l
::
ll2
->
let
ml
=
maximum
l
in
let
mll2
=
maximum2
ll2
in
match
ml
,
mll2
with
|
Aucun
,
m
->
m
|
m
,
Aucun
->
m
|
Int
m1
,
Int
m2
->
if
m1
<
m2
then
Int
m2
else
Int
m1
;;
maximum2
[
[
2
;
3
];
[
4
;
1
];
[
1
;
6
;
8
]];;
maximum2
[
[]
;
[
1
];
[
0
;
0
]];;
maximum2
[
[]
;
[]
];;
maximum2
[]
;;
```
This diff is collapsed.
Click to expand it.
cm/lifpf-cm2.pdf
0 → 100644
+
0
−
0
View file @
ddf57466
File added
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment