63 lines
No EOL
5.1 KiB
HTML
63 lines
No EOL
5.1 KiB
HTML
<!DOCTYPE html>
|
|
<!-- Page generated by OCaml with Ocsigen.
|
|
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
|
<html class="ada2" lang="fr" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>mission2.ml</title><meta content="text/html; charset=utf-8" http-equiv="content-type"/><link media="all" href="../../../ystyle.css" rel="stylesheet"/><script src="../../../Scripts/yfold.js"></script></head><body><div class="header" id="header"><h1 id="title">mission2.ml</h1></div><main><code class="page block"><span class="comment">(* Version OCaml de l'exercice sur les intervalles *)</span>
|
|
|
|
<span class="kw">type</span> t_intervalle =
|
|
{ inf: float ;
|
|
sup: float }
|
|
|
|
<span class="kw">let</span> <span class="letvar">sof</span> x = string_of_int (int_of_float x)
|
|
|
|
<span class="comment">(* Les trois premières fonctions demandées. *)</span>
|
|
<span class="kw">let</span> <span class="letvar">intervalle_image</span> it = <span class="string">"["</span> ^ sof it.inf ^ <span class="string">", "</span> ^ sof it.sup ^ <span class="string">"]"</span>
|
|
<span class="kw">let</span> <span class="letvar">est_inclus</span> a b = (a.inf >= b.inf && a.sup <= b.sup)
|
|
<span class="kw">let</span> <span class="letvar">disjoints</span> a b = (a.sup < b.inf || a.inf > b.sup)
|
|
|
|
<span class="comment">(* Fonction d'affichage générique qui marchera pour t_intervalle et pour t_prod. *)</span>
|
|
<span class="kw">let</span> <span class="letvar">affichage_gen</span> f_inclus f_disjoint f_image i1 i2 =
|
|
<span class="kw">let</span> <span class="letvar">s1</span> = f_image i1
|
|
<span class="kw">and</span> <span class="letvar">s2</span> = f_image i2 <span class="kw">in</span>
|
|
|
|
<span class="kw">if</span> f_inclus i1 i2 <span class="kw">then</span> <span class="uident">Printf</span>.printf <span class="string">"%s est inclus dans %s\n"</span> s1 s2
|
|
<span class="kw">else</span> <span class="kw">if</span> f_inclus i2 i1 <span class="kw">then</span> <span class="uident">Printf</span>.printf <span class="string">"%s est inclus dans %s\n"</span> s2 s1
|
|
<span class="kw">else</span> <span class="kw">if</span> f_disjoint i1 i2 <span class="kw">then</span> <span class="uident">Printf</span>.printf <span class="string">"%s et %s sont disjoints\n"</span> s1 s2
|
|
<span class="kw">else</span> <span class="uident">Printf</span>.printf <span class="string">"%s et %s ne sont pas disjoints, ni inclus\n"</span> s1 s2
|
|
|
|
<span class="comment">(* Afficher_relation pour les intervalles. *)</span>
|
|
<span class="kw">let</span> <span class="letvar">afficher_relation</span> = affichage_gen est_inclus disjoints intervalle_image
|
|
|
|
<span class="comment">(* Produit cartésien *)</span>
|
|
<span class="kw">type</span> t_prod =
|
|
{ left: t_intervalle ;
|
|
right: t_intervalle }
|
|
|
|
<span class="comment">(* Les trois premières fonctions pour les produits cartésiens. *)</span>
|
|
<span class="kw">let</span> <span class="letvar">prod_image</span> p = intervalle_image p.left ^ <span class="string">" x "</span> ^ intervalle_image p.right
|
|
<span class="kw">let</span> <span class="letvar">prod_est_inclus</span> a b = est_inclus a.left b.left && est_inclus a.right b.right
|
|
<span class="kw">let</span> <span class="letvar">prod_disjoints</span> a b = disjoints a.left b.left || disjoints a.right b.right
|
|
|
|
<span class="comment">(* La fonction d'affichage demandée. *)</span>
|
|
<span class="kw">let</span> <span class="letvar">prod_afficher_relation</span> = affichage_gen prod_est_inclus prod_disjoints prod_image
|
|
|
|
<span class="kw">let</span> <span class="letvar">prod</span> a b = { left = a ; right = b }
|
|
|
|
<span class="comment">(* Test *)</span>
|
|
<span class="kw">let</span> () =
|
|
<span class="kw">let</span> <span class="letvar">c</span> = { inf = <span class="number">5.0</span> ; sup = <span class="number">10.0</span> }
|
|
<span class="kw">and</span> <span class="letvar">d</span> = { inf = <span class="number">7.0</span> ; sup = <span class="number">8.0</span> }
|
|
<span class="kw">and</span> <span class="letvar">e</span> = { inf = <span class="number">4.0</span> ; sup = <span class="number">6.0</span> }
|
|
<span class="kw">in</span>
|
|
|
|
afficher_relation c d ;
|
|
afficher_relation d c ;
|
|
afficher_relation c e ;
|
|
afficher_relation d e ;
|
|
|
|
prod_afficher_relation (prod c c) (prod d d) ;
|
|
prod_afficher_relation (prod c d) (prod d c) ;
|
|
prod_afficher_relation (prod d c) (prod e c) ;
|
|
()
|
|
|
|
|
|
</code></main><footer><small class="pcom"><a class="caml_c" href="../../../yversion.html" data-eliom-c-onclick="UJHGP0o9lEGA">Version information</a></small><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:73px;height:28px;" alt="INSA logo" src="../../../Images/logo-insa-light.jpg"/></a><a target="_blank" href="http://jigsaw.w3.org/css-validator/check/referer"><img title="Validate css stylesheet" style="width:28px;height:32px;" alt="CSS3 logo" src="../../../Images/css3.png"/></a><a target="_blank" href="http://validator.w3.org/check/referer"><img title="Validate html5 content" style="width:32px;height:32px;" alt="HTML5 logo" src="../../../Images/html5.png"/></a></footer></body></html> |