This commit is contained in:
Arkitu 2026-01-13 15:00:39 +01:00
parent 2366416df4
commit 0a2df4c9d3
6 changed files with 109 additions and 0 deletions

26
tp7/ocaml/dune-project Normal file
View File

@ -0,0 +1,26 @@
(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

3
tp7/ocaml/exo2/dune Normal file
View File

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

43
tp7/ocaml/exo2/exo2.ml Normal file
View File

@ -0,0 +1,43 @@
type 'a tr = {
mutable taille : int;
mutable donnees : 'a array
};;
let creer_tr capacity init_value = {
taille = 0;
donnees = Array.make (max capacity 1) init_value
};;
let taille_tr tr = tr.taille;;
let acces_tr tr i =
if i >= tr.taille then
invalid_arg "Index bigger than tr size"
else
tr.donnees.(i);;
let modif_tr tr i value =
if i >= tr.taille then
invalid_arg "Index bigger than tr size"
else
tr.donnees.(i) <- value;;
let append_tr tr value =
let n = Array.length tr.donnees in
if tr.taille >= n then
tr.donnees <- Array.init
(n*2)
(fun i -> tr.donnees.(i mod n));
tr.donnees.(tr.taille) <- value;
tr.taille <- tr.taille + 1
;;
let pop_tr tr =
if tr.taille <= 0 then
invalid_arg "Empty tr"
else
tr.taille <- tr.taille - 1;
tr.donnees.(tr.taille)
;;

4
tp7/ocaml/test/dune Normal file
View File

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

1
tp7/ocaml/test/test.ml Normal file
View File

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

32
tp7/ocaml/tp7.opam Normal file
View File

@ -0,0 +1,32 @@
# 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)"]