reorganize ocaml code

This commit is contained in:
Arkitu 2026-01-13 23:23:08 +01:00
parent 0830136fb8
commit 0c91a805e4
62 changed files with 198 additions and 546 deletions

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

9
dm4/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name dm4)
(modules dm4)
)
(executable
(name test)
(modules test)
(libraries dm4)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name dm4)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name dm4)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name lib)
(public_name dm4))

View File

@ -1,4 +1,4 @@
open Lib;;
open Dm4;;
assert (plusetfois 5 6 = (11, 30));;

View File

@ -1,3 +0,0 @@
(executable
(name test_dm4)
(libraries lib))

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

9
dm5/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name dm5)
(modules dm5)
)
(executable
(name test)
(modules test)
(libraries dm5)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name dm5)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name dm5)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name lib)
(public_name dm5))

View File

@ -1,4 +1,4 @@
open Lib;;
open Dm5;;
assert (rotation
[|

View File

@ -1,4 +0,0 @@
(executable
(name test)
(public_name test)
(libraries lib))

1
dune-project Normal file
View File

@ -0,0 +1 @@
(lang dune 3.20)

4
td3/dune Normal file
View File

@ -0,0 +1,4 @@
(library
(name td3)
(modules td3)
)

5
td4/dune Normal file
View File

@ -0,0 +1,5 @@
(library
(name td4)
(modules td4)
)
(env (dev (flags :standard -w -27-32-39)))

9
td5/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name td5)
(modules td5)
)
(executable
(name test)
(modules test)
(libraries td5)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name td5)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name td5)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name lib)
(public_name td5))

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

View File

@ -1,4 +0,0 @@
(executable
(name test)
(public_name test)
(libraries lib))

View File

@ -1,4 +1,4 @@
open Lib;;
open Td5;;
let l = [5; 3; 9; 0; 5; 0];;
let sorted = [0; 0; 3; 5; 5; 9];;

9
td6/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name td6)
(modules td6)
)
(executable
(name test)
(modules test)
(libraries td6)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name td6)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name td6)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name lib)
(public_name td6))

View File

@ -1,3 +0,0 @@
let radix l =
let r = ref 0 in
let running = ref true in

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

View File

@ -1,4 +0,0 @@
(executable
(name test)
(public_name test)
(libraries lib))

View File

@ -1 +0,0 @@
open Lib;;

3
td6/td6.ml Normal file
View File

@ -0,0 +1,3 @@
(* let radix l =
let r = ref 0 in
let running = ref true in *)

View File

@ -1,15 +0,0 @@
(executable
(public_name exo1)
(name exo1))
(executable
(public_name exo2)
(name exo2))
(executable
(public_name exo3)
(name exo3))
(executable
(public_name exo4)
(name exo4))
(executable
(public_name exo5)
(name exo5))

View File

@ -1,33 +0,0 @@
let rec somme_liste l = match l with
| [] -> 0
| a::q -> a + somme_liste q;;
assert (somme_liste [1; 3; 2] = 6);;
let rec taille_liste l = match l with
| [] -> 0
| _::q -> 1 + taille_liste q;;
assert (taille_liste [1; 3; 2] = 3);;
let rec pow valeur exposant = match exposant with
| 0 -> 1
| i -> valeur * (pow valeur (i - 1));;
assert (pow 4 3 = 64);;
(* On peut remplacer i - 1 par exposant - 1 car les deux noms coexistent. *)
let rec part_ent_log2 nombre =
if nombre = 0 then failwith "Boum !";
(* Il est toujours utile de connaître les exceptions tôt. *)
if nombre = 1 then 0
else 1 + (part_ent_log2 (nombre / 2));;
assert (part_ent_log2 10 = 3);;
let rec est_dans_liste element l = match l with
| [] -> false
| a::q -> a = element || est_dans_liste element q;;
assert (est_dans_liste 2 [1; 3; 2]);;
assert (not (est_dans_liste 4 [1; 3; 2]));;

View File

@ -1,10 +0,0 @@
let biggest l = match l with
| [] -> failwith "Empty list"
| x::q -> List.fold_left
(fun acc a -> max acc a)
x
q
;;
assert (biggest [0; 7; 4] == 7);;

View File

@ -1,3 +0,0 @@
let prod l = List.fold_left (fun acc x -> acc *. x) 1. l;;
assert (abs_float (prod [1.5; 2.; 3.] -. 9.) <= 1e-14 );

View File

@ -1,6 +0,0 @@
let rec is_ordered l = match l with
| a::b::q -> a <= b && is_ordered (b::q)
| _ -> true;;
assert (is_ordered [1; 5; 6]);;
assert (not (is_ordered [5.6; 7.8; 3.]));;

View File

@ -1,18 +0,0 @@
let rec is_ordered l = match l with
| a::b::q -> a <= b && is_ordered (b::q)
| _ -> true;;
let rec is_rev_ordered l = match l with
| a::b::q -> a >= b && is_ordered (b::q)
| _ -> true;;
let rec has_ordering l = match l with
| a::b::q -> if a < b then
is_ordered (b::q)
else if a > b then
is_rev_ordered (b::q)
else has_ordering (b::q)
| _ -> true;;
assert (has_ordering [1; 1; 2; 2; 3]);;
assert (has_ordering [3; 2; 1; 1]);;
assert (not (has_ordering [1; 1; 2; 1]));;

9
tp4/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name tp4)
(modules tp4)
)
(executable
(name test)
(modules test)
(libraries tp4)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name tp4)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name tp4)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name exo1)
)

23
tp4/test.ml Normal file
View File

@ -0,0 +1,23 @@
open Tp4;;
assert (somme_liste [1; 3; 2] = 6);;
assert (taille_liste [1; 3; 2] = 3);;
assert (pow 4 3 = 64);;
assert (part_ent_log2 10 = 3);;
assert (est_dans_liste 2 [1; 3; 2]);;
assert (not (est_dans_liste 4 [1; 3; 2]));;
assert (biggest [0; 7; 4] == 7);;
assert (abs_float (prod [1.5; 2.; 3.] -. 9.) <= 1e-14 );;
assert (is_ordered [1; 5; 6]);;
assert (not (is_ordered [5.6; 7.8; 3.]));;
assert (has_ordering [1; 1; 2; 2; 3]);;
assert (has_ordering [3; 2; 1; 1]);;
assert (not (has_ordering [1; 1; 2; 1]));;

View File

@ -1,2 +0,0 @@
(test
(name test_tp4))

82
tp4/tp4.ml Normal file
View File

@ -0,0 +1,82 @@
(* Exercice 1 *)
let rec somme_liste l = match l with
| [] -> 0
| a::q -> a + somme_liste q;;
assert (somme_liste [1; 3; 2] = 6);;
let rec taille_liste l = match l with
| [] -> 0
| _::q -> 1 + taille_liste q;;
assert (taille_liste [1; 3; 2] = 3);;
let rec pow valeur exposant = match exposant with
| 0 -> 1
| i -> valeur * (pow valeur (i - 1));;
assert (pow 4 3 = 64);;
(* On peut remplacer i - 1 par exposant - 1 car les deux noms coexistent. *)
let rec part_ent_log2 nombre =
if nombre = 0 then failwith "Boum !";
(* Il est toujours utile de connaître les exceptions tôt. *)
if nombre = 1 then 0
else 1 + (part_ent_log2 (nombre / 2));;
assert (part_ent_log2 10 = 3);;
let rec est_dans_liste element l = match l with
| [] -> false
| a::q -> a = element || est_dans_liste element q;;
assert (est_dans_liste 2 [1; 3; 2]);;
assert (not (est_dans_liste 4 [1; 3; 2]));;
(* Exercice 2 *)
let biggest l = match l with
| [] -> failwith "Empty list"
| x::q -> List.fold_left
(fun acc a -> max acc a)
x
q
;;
assert (biggest [0; 7; 4] == 7);;
(* Exercice 3 *)
let prod l = List.fold_left (fun acc x -> acc *. x) 1. l;;
assert (abs_float (prod [1.5; 2.; 3.] -. 9.) <= 1e-14 );;
(* Exercice 4 *)
let rec is_ordered l = match l with
| a::(b::q) -> a <= b && is_ordered (b::q)
| _ -> true
;;
assert (is_ordered [1; 5; 6]);;
assert (not (is_ordered [5.6; 7.8; 3.]));;
(* Exercice 5 *)
let rec is_rev_ordered l = match l with
| a::b::q -> a >= b && is_rev_ordered (b::q)
| _ -> true
;;
let rec has_ordering l = match l with
| a::b::q -> if a < b then
is_ordered (b::q)
else if a > b then
is_rev_ordered (b::q)
else has_ordering (b::q)
| _ -> true;;
assert (has_ordering [1; 1; 2; 2; 3]);;
assert (has_ordering [3; 2; 1; 1]);;
assert (not (has_ordering [1; 1; 2; 1]));;

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

9
tp6/dune Normal file
View File

@ -0,0 +1,9 @@
(library
(name tp6)
(modules tp6)
)
(executable
(name test)
(modules test)
(libraries tp6)
)

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name tp6)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name tp6)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name lib)
(public_name tp6))

View File

@ -1,4 +1,4 @@
open Lib;;
open Tp6;;
assert (correct (Fraction (3, 4)));;
assert (correct (Entier 5));;

View File

@ -1,4 +0,0 @@
(executable
(name test_tp6)
(public_name test_tp6)
(libraries lib))

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

17
tp7/dune Normal file
View File

@ -0,0 +1,17 @@
(library
(name exo2)
(modules exo2)
)
(library
(name exo5)
(modules exo5)
)
(library
(name exo10)
(modules exo10)
)
(executable
(name test)
(modules test)
(libraries exo2 exo5 exo10)
)

4
tp7/exo5.ml Normal file
View File

@ -0,0 +1,4 @@
type 'a lc = {
mutable tete : 'a option;
mutable suivant : 'a lc option
};;

View File

@ -1,26 +0,0 @@
(lang dune 3.20)
(name tp7)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name <author@example.com>")
(maintainers "Maintainer Name <maintainer@example.com>")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name tp7)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html

View File

@ -1,3 +0,0 @@
(library
(name exo2)
(public_name tp7))

View File

@ -1,4 +0,0 @@
(executable
(name test)
(public_name test)
(libraries exo2))

View File

@ -1 +0,0 @@
open Exo2;;

View File

@ -1,32 +0,0 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.20"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
x-maintenance-intent: ["(latest)"]

1
tp7/test.ml Normal file
View File

@ -0,0 +1 @@