summaryrefslogtreecommitdiff
path: root/sem_6/HLIN603/ocaml
diff options
context:
space:
mode:
authorGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
committerGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
commit9fe033ea88c2f705ec18c232873d056e0c229d72 (patch)
tree0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_6/HLIN603/ocaml
Initial commit
Diffstat (limited to 'sem_6/HLIN603/ocaml')
-rw-r--r--sem_6/HLIN603/ocaml/TP2/ex1.caml18
-rw-r--r--sem_6/HLIN603/ocaml/TP2/ex2.caml21
-rw-r--r--sem_6/HLIN603/ocaml/TP2/test.caml21
3 files changed, 60 insertions, 0 deletions
diff --git a/sem_6/HLIN603/ocaml/TP2/ex1.caml b/sem_6/HLIN603/ocaml/TP2/ex1.caml
new file mode 100644
index 0000000..ab3237a
--- /dev/null
+++ b/sem_6/HLIN603/ocaml/TP2/ex1.caml
@@ -0,0 +1,18 @@
+class min ( xi : int ) =
+object ( self )
+ val mutable x = xi
+ method get = x
+ method set n = x <- n
+ method min y = if self#get < y then self#get else y
+end;;
+class min_zero xi =
+object
+ inherit min xi
+ method get = 0
+end;;
+let o1 = new min 4;;
+let o2 = new min_zero 0;;
+o1#min 2;;
+o1#min 7;;
+o2#min 2;;
+o2#min (-2);;
diff --git a/sem_6/HLIN603/ocaml/TP2/ex2.caml b/sem_6/HLIN603/ocaml/TP2/ex2.caml
new file mode 100644
index 0000000..21779af
--- /dev/null
+++ b/sem_6/HLIN603/ocaml/TP2/ex2.caml
@@ -0,0 +1,21 @@
+class account b =
+object (self)
+ val mutable balance = 0.0
+ method get = balance
+ method deposit a = balance<-balance +. a
+ method withdraw a = balance <- balance -. a
+ method print = print_float balance; print_newline()
+ initializer self#deposit b
+end;;
+class interest_account b =
+object
+ inherit account b
+ method interest = balance <- balance +. 5. *. balance /. 100.
+end;;
+class secure_account b =
+object
+ inherit account b as super
+ method withdraw a = if (balance -. a)>=0. then super#withdraw a else failwith "T'as pas l'flouze gros!"
+end;;
+class bank =
+ method
diff --git a/sem_6/HLIN603/ocaml/TP2/test.caml b/sem_6/HLIN603/ocaml/TP2/test.caml
new file mode 100644
index 0000000..a454ab3
--- /dev/null
+++ b/sem_6/HLIN603/ocaml/TP2/test.caml
@@ -0,0 +1,21 @@
+class aa =
+object
+ method print = print_endline("Je suis A")
+end;;
+class bb =
+object
+ inherit aa
+ method print = print_endline("Je suis B")
+end;;
+class cc =
+object
+ inherit bb as superb
+end;;
+class dd =
+object (self)
+ inherit cc as super
+ method print = print_endline("Je suis D")
+ method m = super#print
+end;;
+let a = new dd;;
+a#m;;