Merge css
This commit is contained in:
commit
1eeb19358f
16 changed files with 966 additions and 133 deletions
64
Y/Ada-S1/acteur-gada/gada-graphics.ads.html
Normal file
64
Y/Ada-S1/acteur-gada/gada-graphics.ads.html
Normal file
|
@ -0,0 +1,64 @@
|
|||
<!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>gada-graphics.ads</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">gada-graphics.ads</h1></div><main><code class="page block"><span class="kw">package</span> <span class="fname">GAda.Graphics</span> <span class="kw">is</span><span class="eols">
|
||||
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Attention, l'axe des Y est vers le haut.
|
||||
</span> <span class="comment">--
|
||||
</span><span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Trace un point noir aux coordonnées X,Y
|
||||
</span> <span class="kw">procedure</span> <span class="fname">BlackPoint</span>(<span class="ident">X</span>, <span class="ident">Y</span> : <span class="type">Integer</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Redimensionne la fenêtre graphique, et efface l'image courante.
|
||||
</span> <span class="comment">-- Largeur et hauteur sont en pixels (points)
|
||||
</span> <span class="kw">procedure</span> <span class="fname">Resize</span>(<span class="ident">Largeur</span> : <span class="type">Integer</span> ; <span class="ident">Hauteur</span> : <span class="type">Integer</span>) ;<span class="eols">
|
||||
|
||||
|
||||
</span> <span class="comment">-- Une couleur est caractérisée par trois composantes
|
||||
</span> <span class="comment">-- rouge, vert, bleu, dont la valeur va de 0 (pas de couleur) à 255 (couleur vive).
|
||||
</span> <span class="comment">-- Une couleur est donc un triplet de trois entiers entre 0 et 255.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Par exemple, le blanc correspond à (255,255,255), le rouge à (255,0,0)
|
||||
</span> <span class="comment">-- et le violet à (255,0,255) car c'est un mélange de rouge et de bleu.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">type</span> <span class="type">T_Couleur</span> <span class="kw">is</span> <span class="kw">record</span>
|
||||
<span class="ident">Rouge</span> : <span class="type">Integer</span> <span class="kw">range</span> <span class="number">0</span>..<span class="number">255</span> ;
|
||||
<span class="ident">Vert</span> : <span class="type">Integer</span> <span class="kw">range</span> <span class="number">0</span>..<span class="number">255</span> ;
|
||||
<span class="ident">Bleu</span> : <span class="type">Integer</span> <span class="kw">range</span> <span class="number">0</span>..<span class="number">255</span> ;
|
||||
<span class="kw">end</span> <span class="kw">record</span> ;<span class="eols">
|
||||
|
||||
|
||||
</span> <span class="comment">-- Trace un point de la couleur indiquée
|
||||
</span> <span class="kw">procedure</span> <span class="fname">ColorPoint</span>(<span class="ident">X</span>, <span class="ident">Y</span> : <span class="type">Integer</span> ; <span class="ident">Coul</span> : <span class="type">T_Couleur</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Trace une ligne entres les points (X1,Y1) et (X2,Y2)
|
||||
</span> <span class="kw">procedure</span> <span class="fname">ColorLine</span>(<span class="ident">X1</span>, <span class="ident">Y1</span>, <span class="ident">X2</span>, <span class="ident">Y2</span> : <span class="type">Integer</span> ; <span class="ident">Coul</span> : <span class="type">T_Couleur</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Idem, mais la ligne est noire
|
||||
</span> <span class="kw">procedure</span> <span class="fname">BlackLine</span>(<span class="ident">X1</span>, <span class="ident">Y1</span>, <span class="ident">X2</span>, <span class="ident">Y2</span> : <span class="type">Integer</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Trace un cercle (vide) ou un disque (plein) centré en (X, Y) et du rayon indiqué.
|
||||
</span> <span class="kw">procedure</span> <span class="fname">Cercle</span>(<span class="ident">X</span>, <span class="ident">Y</span>, <span class="ident">Rayon</span> : <span class="type">Integer</span> ; <span class="ident">Coul</span> : <span class="type">T_Couleur</span>) ;
|
||||
<span class="kw">procedure</span> <span class="fname">Disque</span>(<span class="ident">X</span>, <span class="ident">Y</span>, <span class="ident">Rayon</span> : <span class="type">Integer</span> ; <span class="ident">Coul</span> : <span class="type">T_Couleur</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Trace un rectangle coloré
|
||||
</span> <span class="kw">procedure</span> <span class="fname">ColorRectangle</span>(<span class="ident">X</span>, <span class="ident">Y</span>, <span class="ident">Largeur</span>, <span class="ident">Hauteur</span> : <span class="type">Integer</span> ; <span class="ident">Coul</span> : <span class="type">T_Couleur</span>) ;<span class="eols">
|
||||
|
||||
|
||||
</span> <span class="comment">-- Met (Flag => true) ou enlève (Flag => false) la marge grise.
|
||||
</span> <span class="kw">procedure</span> <span class="fname">Avec_Marge</span>(<span class="ident">Flag</span> : <span class="type">Boolean</span>) ;<span class="eols">
|
||||
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Ignorez cette partie
|
||||
</span> <span class="comment">-- qui sert à optimiser la mémoire
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">for</span> <span class="ident">T_Couleur</span> <span class="kw">use</span> <span class="kw">record</span>
|
||||
<span class="ident">Rouge</span> <span class="kw">at</span> <span class="number">0</span> <span class="kw">range</span> <span class="number">0</span>..<span class="number">7</span>;
|
||||
<span class="ident">Vert</span> <span class="kw">at</span> <span class="number">0</span> <span class="kw">range</span> <span class="number">8</span>..<span class="number">15</span>;
|
||||
<span class="ident">Bleu</span> <span class="kw">at</span> <span class="number">0</span> <span class="kw">range</span> <span class="number">16</span>..<span class="number">23</span>;
|
||||
<span class="kw">end</span> <span class="kw">record</span>;<span class="eols">
|
||||
|
||||
</span><span class="kw">end</span> <span class="fname">GAda.Graphics</span> ;
|
||||
</code></main><footer><small class="pcom"><a class="caml_c" href="../../yversion.html" data-eliom-c-onclick="WL9oinEbtDi9">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>
|
15
Y/Ada-S1/acteur-gada/gada-plus.ads.html
Normal file
15
Y/Ada-S1/acteur-gada/gada-plus.ads.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
<!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>gada-plus.ads</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">gada-plus.ads</h1></div><main><code class="page block"><span class="kw">package</span> <span class="fname">GAda.Plus</span> <span class="kw">is</span><span class="eols">
|
||||
|
||||
</span> <span class="comment">-- Cette fonction ouvre une nouvelle fenêtre (fenêtre de dialogue)
|
||||
</span> <span class="comment">-- et demande à l'utilisateur de cliquer sur un fichier.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Elle renvoie le nom du fichier cliqué
|
||||
</span> <span class="comment">-- ou la chaîne vide "" si rien n'a été choisi.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">function</span> <span class="fname">Choisir_Fichier</span> <span class="kw">return</span> <span class="type">String</span> ;<span class="eols">
|
||||
|
||||
</span><span class="kw">end</span> <span class="fname">GAda.Plus</span> ;
|
||||
</code></main><footer><small class="pcom"><a class="caml_c" href="../../yversion.html" data-eliom-c-onclick="AnWUvvThhNOP">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>
|
48
Y/Ada-S1/tps.html
Normal file
48
Y/Ada-S1/tps.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- Page generated by OCaml with Ocsigen.
|
||||
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
||||
<html class="ada1" lang="fr" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>TP Ada S1 - premier semestre</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">TP Ada S1 - premier semestre</h1></div><main><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('88fca160')"><span class="arrow" id="arrow-88fca160">▸</span>Sujets des séances de TP</h2><div class="yfold-content" id="content-88fca160" data-yfold-default="hide"><section class="yfold"><h4 class="yfold-title" onclick="toggleYfold('076fa9ca')"><span class="arrow" id="arrow-076fa9ca">▸</span>Configuration</h4><div class="yfold-content" id="content-076fa9ca" data-yfold-default="show"><div class="warning">À effectuer obligatoirement une fois en début d'année.</div><p>Nous allons configurer une fois pour toutes l'installation <span class="file">emacs/Ada</span> de votre compte personnel. Pour cela, effectuer les opérations suivantes avant de commencer le premier TP (vous n'aurez pas à le refaire aux TPs suivants).</p><ul class="steps"><li>Trouvez le dossier <span class="menu">COMMETUD</span> : il devrait y avoir un lien sur votre bureau.</li><li>Allez dans <span class="menu">Commetud</span>, <span class="menu">1ere Année</span>, <span class="menu">Ada</span>, puis <span class="menu">Setup</span>. </li><li>Lancer le programme <span class="menu">setup-exe</span> en cliquant dessus.</li><li>Répondez aux questions et attendez le message indiquant que l'installation s'est bien passée.En cas de doute, demandez à vos voisins ou à l'encadrant.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('076fa9ca') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h4 class="yfold-title" onclick="toggleYfold('6dffd0aa')"><span class="arrow" id="arrow-6dffd0aa">▸</span>Les sujets</h4><div class="yfold-content" id="content-6dffd0aa" data-yfold-default="hide"><aside class="answers"><h4>Réponses</h4><ul><li>Mission 1, partie 1 : <a class="file caml_c" href="Corriges/thzq/mission0.adb.html" data-eliom-c-onclick="thNb1mN8ffFH">mission0.adb</a></li><li>Mission 1, partie 2 : <a class="file caml_c" href="Corriges/enwx/mission1.adb.html" data-eliom-c-onclick="xnRLjRnEKHk4">mission1.adb</a></li><li>Mission 2 :<ul><li><a class="file caml_c" href="Corriges/ygie/mission2a.adb.html" data-eliom-c-onclick="jGaxvF2slPJk">mission2a.adb</a></li><li><a class="file caml_c" href="Corriges/rgvi/mission2b.adb.html" data-eliom-c-onclick="CtA8/EwTiNdR">mission2b.adb</a></li><li><a class="file caml_c" href="Corriges/xejr/mission2c.adb.html" data-eliom-c-onclick="6MEHYZuAFrtb">mission2c.adb</a></li></ul></li><li>Mission 3 : <a class="file caml_c" href="Corriges/nact/mission3.adb.html" data-eliom-c-onclick="StBgDTNsI5S4">mission3.adb</a></li><li>Pas de corrigé pour la mission 4.</li></ul></aside>Vous avez cinq séances de TP pour effectuer les missions suivantes :<ul class="lessons"><li><a class="caml_c" href="tp-contexte.html" data-eliom-c-onclick="vrJWaLxVKcOT"><span class="lbutton">Contexte</span>Contexte de l'ensemble des TPs</a>. </li><li><a class="caml_c" href="tp-m1.html" data-eliom-c-onclick="vT0WSKW9QLtn"><span class="lbutton">Mission 1</span> Premiers tests.</a>. </li><li><a class="caml_c" href="tp-m2.html" data-eliom-c-onclick="J7d2RIf2fn+9"><span class="lbutton">Mission 2</span> Le vol de démonstration.</a>. </li><li><a class="caml_c" href="tp-m3.html" data-eliom-c-onclick="QQuOBvBbmoCl"><span class="lbutton">Mission 3</span> Visite d'aéroports européens</a>. </li><li><a class="caml_c" href="tp-m4.html" data-eliom-c-onclick="5zIWBHwwDzcw"><span class="lbutton">Mission 4</span> Le voyage interactif</a>. </li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('6dffd0aa') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h4 class="yfold-title" onclick="toggleYfold('de67d706')"><span class="arrow" id="arrow-de67d706">▸</span>Acteurs utilisés</h4><div class="yfold-content" id="content-de67d706" data-yfold-default="hide">Acteurs utilisés au premier semestre :<ul class="file-list"><li><a class="file caml_c" href="acteur-gada/gada-text_io.ads.html" data-eliom-c-onclick="tF0Q5Rwgm4/e">GAda.Text_IO</a></li></ul><section class="yfold sober"><h3 class="yfold-title" onclick="toggleYfold('85ee92be')"><span class="arrow" id="arrow-85ee92be">▸</span>INSA-Air</h3><div class="yfold-content" id="content-85ee92be" data-yfold-default="show"><ul class="file-list"><li><a class="file caml_c" href="acteurs-insa-air/assert.ads.html" data-eliom-c-onclick="DlJ+boKmevcZ">assert.ads</a></li><li><a class="file caml_c" href="acteurs-insa-air/avion_sol.ads.html" data-eliom-c-onclick="WV+HwWzaZOSU">avion_sol.ads</a> — Contrôle de l'avion au sol</li><li><a class="file caml_c" href="acteurs-insa-air/carburant.ads.html" data-eliom-c-onclick="CjPbI8hdftNo">carburant.ads</a></li><li><a class="file caml_c" href="acteurs-insa-air/cartographie.ads.html" data-eliom-c-onclick="L4SQyiqz52Zk">cartographie.ads</a> — Accès aux informations de la carte</li><li><a class="file caml_c" href="acteurs-insa-air/insa_air.ads.html" data-eliom-c-onclick="hIcro6SLnsM2">insa_air.ads</a> — Contrôle de l'avion en vol</li><li><a class="file caml_c" href="acteurs-insa-air/pilote_automatique.ads.html" data-eliom-c-onclick="scWF37X8Bcfb">pilote_automatique.ads</a> — Commande le décollage ou l'atterrissage</li><li><a class="file caml_c" href="acteurs-insa-air/simulation.ads.html" data-eliom-c-onclick="T15Ywafn1t9W">simulation.ads</a> — Contrôle de l'avion au sol en mode SIMULATION</li><li><a class="file caml_c" href="acteurs-insa-air/tour.ads.html" data-eliom-c-onclick="jZsPJFf+QeoT">tour.ads</a> — Communication avec la tour de contrôle</li><li><a class="file caml_c" href="acteurs-insa-air/train.ads.html" data-eliom-c-onclick="FATrOUjzKAPa">train.ads</a> — Contrôle du train d'atterrissage</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('85ee92be') ;
|
||||
//]]>
|
||||
</script></section><br class="bbr"/>Tous les acteurs GAda <small class="pcom">(vous n'en avez pas besoin au premier semestre)</small><section class="yfold sober"><h3 class="yfold-title" onclick="toggleYfold('aee00906')"><span class="arrow" id="arrow-aee00906">▸</span>GAda</h3><div class="yfold-content" id="content-aee00906" data-yfold-default="hide"><ul class="file-list"><li><a class="file caml_c" href="acteur-gada/dfloat.ads.html" data-eliom-c-onclick="jSoCamqGV/Du">dfloat.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-advanced_graphics.ads.html" data-eliom-c-onclick="U6l0NTu4ZVaC">gada-advanced_graphics.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-float_text_io.ads.html" data-eliom-c-onclick="z+EtM2H8ECge">gada-float_text_io.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-graphics.ads.html" data-eliom-c-onclick="TRy1ODMB37vv">gada-graphics.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-integer_text_io.ads.html" data-eliom-c-onclick="9s3PLk4Lze0c">gada-integer_text_io.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-plus.ads.html" data-eliom-c-onclick="I0blie9x+aDs">gada-plus.ads</a></li><li><a class="file caml_c" href="acteur-gada/gada-text_io.ads.html" data-eliom-c-onclick="3TQYqzFJAgsT">gada-text_io.ads</a></li><li><a class="file caml_c" href="acteur-gada/tortue.ads.html" data-eliom-c-onclick="thxexLzGMRPJ">tortue.ads</a></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('aee00906') ;
|
||||
//]]>
|
||||
</script></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('de67d706') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h4 class="yfold-title" onclick="toggleYfold('9c9a879b')"><span class="arrow" id="arrow-9c9a879b">▸</span>Problèmes techniques</h4><div class="yfold-content" id="content-9c9a879b" data-yfold-default="hide"><section><h4>Si emacs plante, voici la marche à suivre : </h4><ul class="steps"><li>Cacher la fenêtre emacs ayant planté (minimiser la fenêtre en cliquant sur le 'moins' en haut à droite).</li><li>Rouvrir le fichier <span class="file">mission1.adb</span><small class="pcom"> (par exemple)</small></li><li>Lorsque vous tentez de modifier le fichier, emacs se plaint de ne pas pouvoir l'éditer, <b>dans ce cas, appuyer sur la touche 's'</b> (comme <i>steal</i><small class="pcom"> ou comme <i> c'est moi le chef </i></small>).</li></ul></section><section><h4>Facultatif : si vous voulez aussi détruire la fenêtre emacs ayant planté</h4><ul class="steps"><li>Ouvrir un TERMINAL (à trouver dans le menu Système, ouvrir une console ou un terminal).</li><li>Dans le terminal, écrire : <code class="inline">xkill</code><small class="pcom"> (puis entrée)</small></li><li>Cliquer sur la fenêtre que vous voulez détruire (la fenêtre du emacs ayant planté).</li></ul></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('9c9a879b') ;
|
||||
//]]>
|
||||
</script></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('88fca160') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('b7896e97')"><span class="arrow" id="arrow-b7896e97">▸</span>Exercices complémentaires</h2><div class="yfold-content" id="content-b7896e97" data-yfold-default="hide">Tous ces exercices sont faisables sur <a target="_blank" href="https://tech.io/playgrounds/53242/programmation-ada-insa/espace-pour-tous-les-exercices">tech-io</a>. Vous devriez être capables d'effectuer les exercices suivants seuls :<ul class="exo-list"><li><a class="caml_c" href="exercices/appel-procedures.html" data-eliom-c-onclick="Fg4JcAN/UQYV">Base : appel de procédure et de fonction</a></li><li><a class="caml_c" href="exercices/divers.html" data-eliom-c-onclick="uQaMbBkz4D+0">Base : exercices divers</a></li></ul>Cet ensemble d'exercices correspond exactement au niveau attendu à l'examen :<ul class="exo-list"><li><a class="caml_c" href="exercices/algorigramme.html" data-eliom-c-onclick="Lv934KiGaoS4">Traduction d'algorigramme</a></li><li><a class="caml_c" href="exercices/record.html" data-eliom-c-onclick="ibnkFg+pnMWe">Passage d'arguments et type article</a></li><li><a class="caml_c" href="exercices/collection.html" data-eliom-c-onclick="lnd7R8M/AFBX">Exercices sur une collection de données</a></li><li><a class="caml_c" href="exercices/analyse-polynome.html" data-eliom-c-onclick="6jSx4qM2B2YM">Recherche d'extremum sur un polynôme</a></li><li><a class="caml_c" href="exercices/complet-s1.html" data-eliom-c-onclick="2zYOzFiNMPuj">Exercice sur TOUT<img class="nice-inline" style="width:187px;height:45px;" alt="Voiture" src="../Images/car0.png"/></a><small class="pcom"> (Sujet posé en 2017)</small></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('b7896e97') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('7814051f')"><span class="arrow" id="arrow-7814051f">▸</span>Compétences et évaluation</h2><div class="yfold-content" id="content-7814051f" data-yfold-default="hide"><section class="card"><h3>Compétences Algorithmiques du semestre 1</h3><p>Le domaine <i>UF Maths-Algo</i> est évaluée par compétences. Les compétences d'algo sont classées dans trois macro-compétences, de difficulté croissante :</p><h4><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>Bases de programmation</h4><small class="pcom">(le minimum vital à acquérir)</small><ul class="resources"><li>Traduire une spécification de sous-programme (boîte) en une déclaration de procédure ou de fonction Ada.</li><li>Distinguer les structures de contrôle <code class="kw">while</code>, <code class="kw">if</code>, et <code class="kw">for</code>. </li><li>Dans une procédure ou fonction, savoir utiliser les arguments.</li><li>Écrire une procédure de test qui invoque une fonction, affiche ses arguments et son résultat.</li><li>Respecter les conventions de présentation (indentation, espacements, commentaires, nommage des variables).</li></ul><br class="bbr"/><h4><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>Éléments d'algorithmique</h4><small class="pcom">(l'objet principal du cours)</small><ul class="resources"><li>Appliquer toutes les règles de construction d'un programme (<b>typage</b>). </li><li>Les programmes sont cohérents et compilent sans erreur.</li><li>Prévoir le résultat d'un programme (<b>sémantique</b>). </li><li>Manipuler les types articles</li><li><mark>Essentiel</mark> : les algorithmes classiques (min, max, moyenne).</li></ul><br class="bbr"/><h4><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>Algorithmique fine</h4><small class="pcom"> (pour obtenir le niveau A+)</small><ul class="resources"><li>Pour le niveau A+ : algorithmes classiques avec un traitement supplémentaire, par exemple filtrage.</li></ul><br class="bbr"/><p>Ces compétences seront évaluées partiellement lors du contrôle Moodle, puis plus complètement lors du contrôle de TP début novembre. Un échec au contrôle Moodle peut être rattrapé par une bonne prestation lors du contrôle de TP.</p><p>Toutes les compétences n'ont pas le même poids. Par exemple, la distinction des blocs <code class="kw">IF</code>, <code class="kw">WHILE</code>, <code class="kw">FOR</code> est a priori plus importante que le respect des conventions de présentation. Un correcteur examinera votre contrôle pour estimer si chaque macro-compétence est acquise. </p><h3>Évaluations</h3><ul><li>Un contrôle Moodle, début octobre. Durée 45 min.</li><li><mark>Évaluation principale : </mark>un contrôle de TP sur ordi, début novembre. Durée 1H30.</li></ul><p>Pendant les évaluations, le seul document autorisé est l'aide-mémoire, possiblement annoté.</p></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('7814051f') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('15018ba3')"><span class="arrow" id="arrow-15018ba3">▸</span>Bibliographie et conseils sur la méthode de travail</h2><div class="yfold-content" id="content-15018ba3" data-yfold-default="hide"><h4>Biblio</h4><ul class="bib"><li><cite>L'algorithmique (votre passeport informatique pour la programmation). </cite><span class="author">Bruno Warin, Ellipses </span><small class="pcom"> (ISBN 2729811400)</small>. </li><li><cite>Initiation à l'Informatique (Programmation, Algorithmique, Architectures). </cite><span class="author">Henri-Pierre Charles, Eyrolles </span><small class="pcom"> (ISBN 2212090498)</small></li><li><cite>Apprendre à programmer (Algorithmes et conception objet), Partie I. </cite><span class="author">Christophe Dabancourt, Eyrolles </span><small class="pcom"> (ISBN 9782212123500)</small></li></ul><h4>Conseils</h4><ul class="steps"><li>Garder un exemplaire propre de votre travail de TD (les TDs sont effectués en équipe de 4, vous devriez avoir quatre exemplaires présentables à l'issue des séances).</li><li>Pendant les séances de TP, reportez à la fin de votre aide-mémoire les <b>erreurs de compilation</b> qui vous posent problème. Elles risquent de se reproduire à l'avenir, y compris en contrôle. Une page est déjà prévue pour cela.</li><li>D'une manière générale (ceci est vrai pour toutes les matières), quand vous avez résolu un problème qui vous semble difficile, écrivez une synthèse de ce qu'il faut en retenir. Le simple fait de rédiger cette synthèse vous aidera à mieux appréhender le problème et à vous en rappeler.</li><li>Entre deux séances de TP, relisez les algorithmes et programmes que vous avez effectué à la séance précédente, en comprenant bien <b>chaque étape</b>. Identifiez dans votre aide-mémoire ce que vous avez appris.</li><li>Rappel : vous pouvez librement contacter vos enseignants de TD, TP ou de cours pour poser des questions.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('15018ba3') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('6eac443c')"><span class="arrow" id="arrow-6eac443c">▸</span>Ada en dehors des heures de TP</h2><div class="yfold-content" id="content-6eac443c" data-yfold-default="hide"><section class="card"><h3>Pour travailler Ada à l'INSA</h3><p>Des salles informatiques sont en accès libre : <b>la salle du CSN</b> (au centre informatique), et les salles du sous-sol si vous parvenez à y accéder.</p></section><section class="card"><h3>Pour travailler Ada depuis chez soi, en se connectant sur un serveur de l'INSA (avec connexion VPN)</h3><ol><li>Avoir une connexion VPN qui fonctionne : <a target="_blank" href="http://csn.insa-toulouse.fr/fr/services/services-transverses/connexion-par-vpn.html">le client VPN de l'INSA</a><br/> ou <a target="_blank" href="https://wiki.etud.insa-toulouse.fr/books/r%C3%A9seau-et-internet">le VPN expliqué par WikEtud</a>. </li><li>Puis visiter : <a class="url" target="_blank" href="https://montp.insa-toulouse.fr">//montp.insa-toulouse.fr</a> et choisir une session linux.</li><li>En cas de problème technique, envoyez un email à <i>infrastructure-csn à insa-toulouse.fr</i>. </li></ol></section><section class="card"><h3>Pour travailler Ada directement sur son propre ordi, chez soi (sans connexion internet)</h3><p>Grâce aux efforts du club info, il est possible d'installer sur son ordinateur personnel un environnement semblable à l'environnement des TP Ada à l'INSA.</p><p>Aucune connaissance technique n'est nécessaire. Il suffit de suivre les consignes indiquées <a target="_blank" href="https://wiki.etud.insa-toulouse.fr/books/tutos/chapter/machine-virtuelle-ada">pour installer une machine virtuelle.</a></p></section><section class="card"><h3>Tech.io (connexion internet, pas de VPN)</h3><p>Alternative : vous pouvez travailler directement sur tech.io :</p><ul><li><a target="_blank" href="https://tech.io/playgrounds/5454/learning-algorithmics-with-ada/welcome">Exercices complémentaires du semestre 1<small class="pcom"> (by le Club Info)</small></a></li><li><a target="_blank" href="https://tech.io/playgrounds/53242/exercices-complementaires-ada">Exercices complémentaires du semestre 2<small class="pcom"> (by Le Botlan)</small></a></li><li><a target="_blank" href="https://tech.io/playgrounds/53242/programmation-ada-insa/espace-pour-tous-les-exercices">Espace sur tech-io pour écrire tous les programmes (hors TP)</a></li></ul></section><p>Enfin, notez que le club INFO vous aide à installer l'environnement - contactez-les.</p></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('6eac443c') ;
|
||||
//]]>
|
||||
</script></section></main><footer><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:194px;height:42px;" alt="INSA logo" src="../Images/logo-insa.jpg"/></a><a target="_blank" href="https://www.laas.fr/"><img title="LAAS" style="width:82px;height:42px;" alt="LAAS logo" src="../Images/laas.png"/></a><a target="_blank" href="http://www.univ-toulouse.fr/"><img title="University of Toulouse" style="width:84px;height:42px;" alt="University of Toulouse logo" src="../Images/univt.jpg"/></a><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="Iarl7eQKHOUu">Version information</a></small><a target="_blank" href="http://ocaml.org/"><img title="Powered by OCaml code" style="width:42px;height:42px;" alt="OCaml logo" src="../Images/ocaml-small.png"/></a><a target="_blank" href="http://ocsigen.org/"><img title="Website generated by ocsigen & eliom" style="width:38px;height:32px;" alt="Ocsigen logo" src="../Images/ocsigen-small.png"/></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>
|
40
Y/Ada-S2/acteur-jpg/jpg.ads.html
Normal file
40
Y/Ada-S2/acteur-jpg/jpg.ads.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
<!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>jpg.ads</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">jpg.ads</h1></div><main><code class="page block"><span class="comment">--
|
||||
</span><span class="comment">-- Ce package permet de lire une image contenue dans un fichier JPG
|
||||
</span><span class="comment">-- ou d'écrire une image vers un fichier JPG.
|
||||
</span><span class="comment">--
|
||||
</span><span class="comment">-- (Utilise simple_jpeg_lib et libjpeg)
|
||||
</span><span class="comment">--
|
||||
</span>
|
||||
<span class="kw">with</span> <span class="ident">GAda.Graphics</span> ;<span class="eols">
|
||||
|
||||
</span><span class="kw">package</span> <span class="fname">JPG</span> <span class="kw">is</span><span class="eols">
|
||||
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Une image est une matrice dont chaque case représente un point coloré.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">type</span> <span class="type">T_Image</span> <span class="kw">is</span> <span class="kw">array</span>(<span class="ident">Natural</span> <span class="kw">range</span> <>, <span class="ident">Natural</span> <span class="kw">range</span> <>) <span class="kw">of</span> <span class="ident">GAda.Graphics.T_Couleur</span> ;<span class="eols">
|
||||
|
||||
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Lit un fichier contenant une image JPEG et renvoie une matrice
|
||||
</span> <span class="comment">-- contenant les pixels de l'image.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="comment">-- Les lignes et colonnes commencent à zéro.
|
||||
</span> <span class="comment">-- L'origine de la matrice (0,0) est située en haut à gauche de l'image.
|
||||
</span> <span class="comment">-- Comme d'habitude, le premier indice est le numéro de ligne, le deuxième indice le numéro de colonne.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">function</span> <span class="fname">Lire_Image</span> (<span class="ident">Nom_Image</span> : <span class="type">String</span>) <span class="kw">return</span> <span class="type">T_Image</span> ;<span class="eols">
|
||||
|
||||
</span>
|
||||
|
||||
<span class="comment">--
|
||||
</span> <span class="comment">-- Crée sur le disque dur un fichier JPG contenant l'image
|
||||
</span> <span class="comment">-- Vous n'avez en principe pas besoin de cette procedure pendant les TPs.
|
||||
</span> <span class="comment">--
|
||||
</span> <span class="kw">procedure</span> <span class="fname">Ecrire_Fichier</span> (<span class="ident">Nom_Image</span> : <span class="type">String</span> ; <span class="ident">Matrice</span> : <span class="type">T_Image</span>) ;<span class="eols">
|
||||
|
||||
</span><span class="kw">end</span> <span class="fname">JPG</span> ;
|
||||
</code></main><footer><small class="pcom"><a class="caml_c" href="../../yversion.html" data-eliom-c-onclick="2FnsmjHo+/iI">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>
|
64
Y/Ada-S2/tp-m1.html
Normal file
64
Y/Ada-S2/tp-m1.html
Normal file
|
@ -0,0 +1,64 @@
|
|||
<!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>Partie 1 (2H environ) : Manipulation de caractères</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">Partie 1 (2H environ) : Manipulation de caractères</h1><nav><a class="caml_c" title="Back to main page" href="tps.html" data-eliom-c-onclick="gfTnxn62lNv8"></a></nav></div><main><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('1d669c0b')"><span class="arrow" id="arrow-1d669c0b">▸</span>Objectifs</h2><div class="yfold-content" id="content-1d669c0b" data-yfold-default="show"><ul class="goals"><li>Parcourir les tableaux et matrices. </li><li>Exploiter l'information d'une structure imbriquée.</li></ul><h4>Prérequis</h4><ul class="requires"><li>À la première séance de TP, vous avez fait une bonne partie des exercices de préparation : <a class="caml_c" href="exo-traces.html" data-eliom-c-onclick="qAkNdhiy4PZ+">Exercice de tracés avec des caractères</a> et <a class="caml_c" href="exo-intervalles.html" data-eliom-c-onclick="7c2pXeamkvmC">Exercice avec des types article</a>. </li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('1d669c0b') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('e919c091')"><span class="arrow" id="arrow-e919c091">▸</span>Mission 1</h2><div class="yfold-content" id="content-e919c091" data-yfold-default="hide"><p>La transformation d'une image en Ascii-Art (voir image ci-contre) nécessite de manipuler des caractères (des lettres), ceux qui servent à reconstituer l'image. Dans ce premier TP, nous nous concentrons donc sur la forme graphique des caractères, fournie sous forme de matrice. </p><section class="yfold card"><h4 class="yfold-title" onclick="toggleYfold('21bb4a14')"><span class="arrow" id="arrow-21bb4a14">▸</span>Descente dans la table</h4><div class="yfold-content" id="content-21bb4a14" data-yfold-default="hide"><pre class="ascii">
|
||||
```````
|
||||
```'''````` ``````'''`,,`
|
||||
```'` ``'``
|
||||
,`' ''``
|
||||
,'` `^,
|
||||
`,' `'`
|
||||
,,!~..`````````````````````,`'`,,``````````````````'''.'!,,
|
||||
|'~ws\~` `/kx^^''~!, `,~x?J~~`
|
||||
`-' `~*.-,-'``,` *XO**^*\k);` `,,--^./r!~' ^-`
|
||||
_' ' `^',` `^,``` *5Q[jx/]%*/ `,,-'` ``,--` -`'`
|
||||
_' ',,,` `''',._``,-'^-%%{*/~7Y)--_^^'```,,`''' ```_` ^`
|
||||
`^ xcanr_~~,``'''^-''^-~~'``^^'^~,'^~``!_.~'~-,-''''''--:!x)=v` ^`
|
||||
^ ''`'''^^''``-,---'',,.~~, ` `.x,,,,,^',``',,'--+^~~'^` ^
|
||||
~` ' =0r^,--~'+-!x` -` `.
|
||||
' ' ' ` '^ -` '
|
||||
`^ ' -` `' -` ^`
|
||||
'` ' '' ` _ ```' _` `,
|
||||
'` ' x' ^ `~ ^` `,
|
||||
`, ' `' ` !` -` `'
|
||||
' ' `~` ``,'_ '' -` _`
|
||||
' ' ````` `''~` ,`, ^` '
|
||||
`. ' `` ' `'`^^, ' , -` ``
|
||||
^` ' ' `,`` `' '` ' _` -` `'
|
||||
^ ' ,' `,^ ~' `'' `' -` ^
|
||||
^ ' `-```-`' .'` ,-,` '` -``-
|
||||
-`' `-` `-` .` `-^' `' ',`'!` -'-
|
||||
'' .' `' _``.`'`'.` ^` ^, ~^
|
||||
`^` `^ `' ,` `', `^ ' ` `. `-^`
|
||||
`' '` . ,` ' '. , ', ,` `'` -`
|
||||
`' `` `'`' '` .'` , `,` -` `'` _`
|
||||
`' ``^--`^ ' ^ ~ , '. '-,_.,'` -`
|
||||
`' `^-~' `'`-`^ ! ^_`.,^` ^`
|
||||
`' `` ,-`^`'`'''` ```'` ,`
|
||||
`-'''''''''''''''''''---+*Y!+~=^''''--~-'''````````````````-`
|
||||
</pre><ul class="steps"><li>Créez un dossier pour tous vos prochains TPs d'algo, nommez-le <span class="hfile">algo2</span> (sans espace !). Copiez-y le fichier <span class="file">mission1.adb</span> que vous trouvez sur commetud. </li><li>Écrire un programme <var>Mission1</var> qui demande poliment à l'utilisateur de taper un entier (n) et qui affiche ensuite la valeur de n. Testez.</li><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span> Complétez votre programme : affichez ensuite le caractère contenu dans la n-ème case de la table, avec <code class="inline">GAda.Text_IO.Put(Aff : character)</code>. <section class="advice"><div class="content"><ul><li>Pour tester : le caractère numéro 32 est un 'C'.</li><li>Il vous faut bien comprendre l'acteur <a class="file caml_c" href="acteur-jpg/caracteres.ads.html" data-eliom-c-onclick="K1+GdZu2su0o">Caracteres</a>. Pour cela, réfléchissez à deux, et lisez ces commentaires : </li><li>L'information que l'on cherche se trouve dans la variable <var>Table</var>. C'est un <b>tableau</b> (<code class="inline">array</code>). Voyez votre poly pour comprendre ce qu'est un tableau.</li><li>Chaque case de ce tableau contient un type article <code class="inline">T_Paire</code> (chaque case est différente). </li><li>On vous demande d'afficher le caractère contenu dans cet article.</li><li>En résumé, il faut donc trouver comment accéder à la N-ème case de la <var>Table</var>, et obtenir le caractère contenu dans le type article présent dans cette case.</li></ul></div></section></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('21bb4a14') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold card"><h4 class="yfold-title" onclick="toggleYfold('adfb12d4')"><span class="arrow" id="arrow-adfb12d4">▸</span>Parcours de matrice</h4><div class="yfold-content" id="content-adfb12d4" data-yfold-default="hide"><ul class="steps"><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>Ajoutez un sous-programme : la procédure <code class="block">Afficher_Trame</code><img class="space" title="Afficher_Trame" style="width:343px;height:50px;" alt="Procedure Afficher_Trame" src="../Gen/Afficher_Trame-1-b52-.png"/>Pour afficher la trame, on parcourt la matrice ligne par ligne et colonne par colonne. Si la case contient un pixel allumé, on affiche un <var>#</var><small class="pcom"> (avec GAda.Text_IO.Put), </small>si le pixel est éteint, un espace. <br/><section class="advice"><div class="content">Pour détecter si le pixel est éteint ou allumé, utiliser un <b>bloc CASE</b>. </div></section></li><li>Pensez à ajouter une procédure de test : <code class="block">Tester_Afficher_Trame</code> qui affiche la trame de 3 ou 4 caractères de votre choix. <img class="space" title="Tester_Afficher_Trame" style="width:235px;height:50px;" alt="Procedure Tester_Afficher_Trame" src="../Gen/Tester_Afficher_Trame-0-c97-.png"/></li><li>Écrivez une procédure <code class="block">Afficher_Mot</code> qui reçoit en argument une chaîne (<var class="type">String</var>) et qui affiche verticalement les trames des caractères de cette chaîne. Si vous avez besoin de créer une fonction auxiliaire, c'est normal.<img class="space" title="Afficher_Mot" style="width:290px;height:50px;" alt="Procedure Afficher_Mot" src="../Gen/Afficher_Mot-1-78e-.png"/><section class="advice"><div class="content">Le type <var class="type">String</var> est un tableau de <var class="type">Character</var> : <br/><code class="block"><span class="kw">type</span> <span class="type">String</span> <span class="kw">is</span> <span class="kw">array</span>(<span class="ident">Integer</span> <span class="kw">range</span> <>) <span class="kw">of</span> <span class="ident">Character</span>
|
||||
</code><br/>Le numéro de la première case n'est pas forcément <code class="inline">1</code>, il s'obtient avec la notation <code class="inline">'First</code>. </div></section></li><li>Testez en affichant votre nom.</li><li><span class="lbutton">Défi (facultatif)</span>(Si vous êtes en avance) afficher maintenant votre nom horizontalement. N'oubliez pas d'écrire d'abord l'algorigramme sur papier.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('adfb12d4') ;
|
||||
//]]>
|
||||
</script></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('e919c091') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('edf0389a')"><span class="arrow" id="arrow-edf0389a">▸</span>Acteurs utilisés</h2><div class="yfold-content" id="content-edf0389a" data-yfold-default="hide"><ul class="file-list"><li><a class="file caml_c" href="../Ada-S1/acteur-gada/gada-text_io.ads.html" data-eliom-c-onclick="u4xARMFAStEG">GAda.Text_IO</a></li><li><a class="file caml_c" href="../Ada-S1/acteur-gada/gada-integer_text_io.ads.html" data-eliom-c-onclick="HpGnIS+9/+EO">GAda.Integer_Text_IO</a></li><li><a class="file caml_c" href="acteur-jpg/caracteres.ads.html" data-eliom-c-onclick="j38sV1e1Pf2i">Caracteres</a></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('edf0389a') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('644a65bb')"><span class="arrow" id="arrow-644a65bb">▸</span>Bilan</h2><div class="yfold-content" id="content-644a65bb" data-yfold-default="hide"><ul class="success"><li>Une matrice dans un type article dans un tableau ne vous fait pas peur.</li><li>..mais saurez-vous manipuler un type article dans une matrice ? (cf <a class="caml_c" href="tp-m2.html" data-eliom-c-onclick="cM3G/zHGY24B">Mission 2</a>)</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('644a65bb') ;
|
||||
//]]>
|
||||
</script></section></main><footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="020TtW4+L8N/">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>
|
63
Y/Ada-S2/tp-m2.html
Normal file
63
Y/Ada-S2/tp-m2.html
Normal file
|
@ -0,0 +1,63 @@
|
|||
<!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>Partie 2 (3H environ) : Manipulation d'image</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">Partie 2 (3H environ) : Manipulation d'image</h1><nav><a class="caml_c" title="Back to main page" href="tps.html" data-eliom-c-onclick="XZ0PS9odE233"></a></nav></div><main><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('12e7899e')"><span class="arrow" id="arrow-12e7899e">▸</span>Objectifs</h2><div class="yfold-content" id="content-12e7899e" data-yfold-default="show"><ul class="goals"><li>Afficher et transformer une image (parcours d'image et utilisation de l'acteur graphique.)</li></ul><h4>Prérequis</h4><ul class="requires"><li>Vous avez terminé <a class="caml_c" href="tp-m1.html" data-eliom-c-onclick="Fji4IwKNfYi2">la première partie sur les caractères</a></li><li>Vous savez qu'une image est composée de points colorés appelés <i>pixels</i>. </li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('12e7899e') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('56c6586d')"><span class="arrow" id="arrow-56c6586d">▸</span>Mission 2</h2><div class="yfold-content" id="content-56c6586d" data-yfold-default="hide"><p>Nous nous intéressons maintenant à la manipulation d'images.</p><section class="yfold card"><h4 class="yfold-title" onclick="toggleYfold('903b1d78')"><span class="arrow" id="arrow-903b1d78">▸</span>Etape 1</h4><div class="yfold-content" id="content-903b1d78" data-yfold-default="hide"><pre class="inv-ascii">((*<<)*>:)<<</~~^/:\::;^:/\\\:~v;*/vv;\)*()v/\/(\((v(:^:v(+)/+:~:/(+(;;v~:::(//:)++:)/::r(\)/
|
||||
<(<<>)<<:/:lr)+!~;(:/\\;:v\://i</</(*;\v))<*+/:)()vv</~:(*+):~)~\;v/v\iv~:::(;/:*;\:(\(:/)/(/
|
||||
<<<<<<<~=<nCsp]=~+\CpSyZt^://;/\i)/<*~//(><(;<<></(><:~/vv~)/~(;/;(/*:;<~:::(//:);/:(/(:i*/)\
|
||||
<)<<<vr/V3VP&&3>~<>;~\:r+(\;r;:=:::**~\:*<<:(<<<<;(<<)~~*v~((~:;;+:;*:;*^::;/;/+*+r:)/):/)/v/
|
||||
<)>*~x&&t*h?rT+/~.~~'^=~;v:;r/;~>;*;)~;)<<>:v<<><):<<(~~<*~(*~(\;\;\*~'^-\(` _:'''^+*::*\)/
|
||||
<<<^x3&&&Gst*+^' `<! -\:\)+|<+*/>i;)><<(><<<<</<<+^^/;^;(^(\;/;i:.,` ` ```_.+(::(/*:
|
||||
<*<^2VVVsJri'. -.=!.`` -vr*+;</</>i;(<x<v<>><x<+*~.',-^,(/!(:\::/v\:<^~^---.;://<)/<::<:*v
|
||||
<v<*:vvv;:~' ,` _.</~~++(v<;;>r</<;;v<>x:<<x><*;*^-.',~v(+~*/;/:\>/r^' ',` `=:<(/>v:<(v:
|
||||
>*<<x<<<*)(+ .=+-\+:~~(~<v<;i>L<r<)v>x<f>:<<><~:(\^=;^^((~~v/;/(+<\:\':):' '/:>::v/:((*)
|
||||
<vx<<<<<(((|l' f}/sL^\^~*;*:>~ixewvxe4Gexzsrv)>(~*<v*/v:!~*/~*+:/*/>/r<~()\ -/:<(:*v:((v:
|
||||
<)<<<<<<(*)(i~ `|ivw~>:~;*/(:>L::(<Ls&K0aa0Gkx):/~)****v(/^<:~(~(/*\v:r<i((:. +;;/::v/(::(/
|
||||
</><<<<(:(**()`_FoVr~(\^;*\:;a&2Y(xr<sF}s2333s*><~:((v(/<:^<*~)+(~*=v:;*~():;` .` `,~(/:::(\
|
||||
>/<<<:(:~~~::/,/~sT;~;^'~(/:+fFF?1xLCy&&&000P<JZC:)**v(:<:^<*~(|v+:;::~-`,^~^- ` `--`-\/:/:\:
|
||||
<v</^/0^!..,'~++,~+()(^.;;;;ixo0&g&m&gX&&04k<(::\+(<<<(:((^((~v~<r(+/;```.!_' . -. -\(//:/
|
||||
<(~.~\V^^^.,,```_~i::/~^;(\;iV0XX555555g&3Gkx>;~;;<<<><v((~)v=>+<\T~:!''.;\`` ~i| =\(/):/
|
||||
<(,^=+/((~ ^' `~=~/++^-^^^^^/T~T5XXX&&&3S000Sr/;\<<>>>v;:~;T~:~:~\!^' '^~~ `:/- ^/:/v::
|
||||
<;:(>(v)~ ` :x^;;.`,`'`.._/*fVh(*V&300HX&&[+;;oo*<v://^i\~/^/^` ` ,`_+!' ^!=`` `'~(::
|
||||
(:<(*:v)` '` +x~irv'^!.=^!^^'~;^zw4O&&&0&4&*i*4&p<*()\/~;:~:^\~+..=~~--/v -/!;'~!_.,/;/
|
||||
)((()(())+T~x):;=xl/(+=+.^~~~;^xw&ggggXXXO300P1zxf>>**((\)/~(~\!/^~+|/~!` '' `` '-` `\;)\:+:
|
||||
(:(//::)(~,-,```/>|'|:r=/C(I(~v&X5XgX&XXb&P}C4&&3af<**<)r*(~(^\|/^~~|/+- `!::;` '~\;\/(~:
|
||||
)*(::::::,```/',^+\i+'<++<>\!(*4P4Y30230S0mkqXX&0Z><*>*)~*(~*~/!;^+!+:' .::\/(/` -i\/:/(;:
|
||||
<<(:/://:^```,',,`-\)\!.!~i~~(/C<>>hy000S0k<xVaPF\:**<*(~((~(|/!:~+|iv.` ,((:/:)(| +/:(/:/:
|
||||
xzjjv<v(/!' `!,-|-i>xv~:(\:<o*>^{{x~<CFFxsxxv~~~~;/<<*:~(:~v!(~:~;|+v+` ;:::/:::/ .;:::://:
|
||||
XX&&XX&X&k'` `qpx.^,<suswkC}uz:x;j)<~<x^shkx>:^~~^;\<<(v~)(~v!/!(~/+~)- ^/://;(:/` ^;(//;/\\
|
||||
XXXXXXXXXk`' +&&r,''+VXX55gggg5g5gggg555XX&&2aapwpppwwwuwsusLxIxL>:;>` -;;+/;\:_ +;\~~^+;
|
||||
XXXXXXXXX&o+```sXk,~`'`^0g55555g555555gg55gg55555555555555g550k?r~~^!|iLna&0Ps*r^-_.=ouoL::~~
|
||||
X5XXXX5XXXk_``=&X5S&s```)X55555gg5555555g555555555gg2k7T\~'^!|icop&&X0V?T~'_=:xs2g55g5gg55gg5
|
||||
XX555XgXXF>vi.&XXgX&Y'``aXgg5X5555555555550VF*\~',-_!icop05ggg0h*r~'_.;ns4ggggg5g55555g555555
|
||||
XXXXXXXXS?&X[^aXXXXf\=.~&555XXX550sF*r^,,_.|ivnsa&g5g53VF*\~'.=Lnsmggg55g5g55555g55gg5g555555
|
||||
XXXXXXXX/T(T~0XXXXPs&(f^w7T;^',_'_|=Lco0g5g55g5&UF*\^''=ixs0g5gg555555g555g55g55g5555g55g5g55
|
||||
XXXXXXXe~~``*r~/h?~*Y+! `!iLxopSX55555&aF*~'-'.=Lxsa&5555g555g5555555g5ggg55gg55555555555555
|
||||
XXXX&&p\T-`.````_.,i,`oP3XXX5gXgGk*~',``_|ivzp&g55555g55555555g5555555g555555555555555g5g5555
|
||||
XXX4:~o=-_ivnw0XXr+-``'~?*T~,,,``_!ivo3gg5gg555555g55ggg5gg555555g55555g5gg5555g5555555555555
|
||||
XXX&ppXXXXXX&FfkF-~,r-````_|:xsS55gg5g555g555555555555555555g555555g5g5g5555555g555555555g555
|
||||
XXXgXXXggXXXk1*0&si~\vopXg55g555g5555g55555g55555g5g555g555555555555g555g55g55555555g555g5555
|
||||
</pre><ul class="steps"><li>Dans votre dossier algo2, copiez une image <b>JPG</b> de bon goût, de taille maximale 800x600 <b>qui n'ait aucun axe de symétrie. </b>À défaut, prenez cette <a class="caml_c" href="../Images/mononoke.jpg" data-eliom-c-onclick="UBZyB+4Y8Xzo">affiche de film</a> <i>(clic-droit sur le lien : enregistrer la cible du lien...)</i></li><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>Écrivez un nouveau programme <var>Mission2</var>, ajoutez une procédure <code class="block">Afficher_Image</code> qui prend en argument une image (de type <var class="type">T_Image</var>) et qui l'affiche. <br/>Le type <var class="type">T_Image</var> est défini dans l'<a class="file caml_c" href="acteur-jpg/jpg.ads.html" data-eliom-c-onclick="p7gl6zeocsO+">acteur JPG</a>. et l'affichage se fait grâce à l'acteur <a class="file caml_c" href="../Ada-S1/acteur-gada/gada-graphics.ads.html" data-eliom-c-onclick="o/UQ31xXFYqL">GAda.Graphics</a>. <img class="space" title="Afficher_Image" style="width:323px;height:50px;" alt="Procedure Afficher_Image" src="../Gen/Afficher_Image-1-597-.png"/></li><li>Écrivez une procédure de test <code class="block">Tester_Afficher_Image</code> qui demande à l'utilisateur de choisir un fichier jpg et qui l'affiche. <ul><li>Voyez l'acteur <a class="file caml_c" href="../Ada-S1/acteur-gada/gada-plus.ads.html" data-eliom-c-onclick="4tRBhSTRsrTF">GAda.Plus</a> pour choisir un fichier. </li><li>Rappelez-vous qu'on ne définit pas de variable de type String, seulement des constantes, avant le <code class="kw">begin</code>. </li></ul><img class="space" title="Tester_Afficher_Image" style="width:235px;height:50px;" alt="Procedure Tester_Afficher_Image" src="../Gen/Tester_Afficher_Image-0-c97-.png"/><section class="advice"><div class="content">Il n'est pas nécessaire de donner la taille d'un tableau ou d'une matrice lorsqu'on l'initialise immédiatement, par exemple <code class="block">ZImage : T_Image := <i>(quelque chose de type T_Image)</i> ;</code></div></section></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('903b1d78') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold card"><h4 class="yfold-title" onclick="toggleYfold('f7c7425a')"><span class="arrow" id="arrow-f7c7425a">▸</span>Etape 2</h4><div class="yfold-content" id="content-f7c7425a" data-yfold-default="hide"><ul class="steps"><li>Modifiez la procédure <code class="inline">Afficher_Image</code> pour qu'elle prenne deux arguments supplémentaires : les coordonnées où l'on veut afficher l'image. <img class="space" title="Afficher_Image" style="width:323px;height:50px;" alt="Procedure Afficher_Image" src="../Gen/Afficher_Image-3-451-.png"/>Testez en ouvrant une fenêtre deux fois plus large et deux fois plus haute que l'image, et en affichant l'image décalée de +(120,80). Vous devez obtenir ceci : <img class="space" style="width:160px;height:200px;" alt="Exemple avec l'image originale translatée." src="../Images/image-decalee.png"/></li><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span>En créant quatre variantes de votre procédure d'affichage, afficher l'image avec différents filtres : <ul><li>Une fois en normal (Afficher_Image)</li><li>En <b>permutant les composantes</b> rouge, verte, bleue (par exemple, la composante verte prend la valeur du rouge, et la composante rouge prend la valeur du bleu, etc.).</li><li>En <b>négatif</b> (chaque composante de couleur <var>z</var> devient <var>255-z</var>)</li><li>En <b>noir et blanc</b> (tons de gris, obtenus en prenant chaque composante égale à la luminosité). <br/>La luminosité d'un pixel se calcule en faisant la moyenne des trois couleurs<small class="pcom"> (en réalité, la moyenne devrait être pondérée en fonction de la sensibilité de l'oeil humain aux différentes couleurs)</small>. <img class="space" style="width:160px;height:200px;" alt="Exemple avec quatre images dans un rectangle." src="../Images/image-4.png"/></li></ul></li><li><span class="lbutton">Facultatif</span><small class="pcom">(À laisser si vous êtes en retard) : </small><ul><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span><b>"Floutage" </b> (rendre l'image floue) : on rend l'image floue en remplaçant chaque pixel <var>(x,y)</var>par une moyenne des pixels situés dans un carré de taille n centré en <var>(x,y)</var>. <br/>Testez avec n = 5, 10, 20.</li><li><span class="difficulty"><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/><img style="width:16px;height:16px;" alt="Star" src="../Images/etoile.png"/></span><b>Détection de contours </b> : remplacer chaque pixel par le gradient de la luminosité au point considéré. Pour ceux qui ont peur des gradients, ne prendre que le gradient horizontal, i.e. la dérivée de la luminosité selon l'axe des X. Voir filtre de Sobel sur Wikipedia.</li></ul></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('f7c7425a') ;
|
||||
//]]>
|
||||
</script></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('56c6586d') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('a94505db')"><span class="arrow" id="arrow-a94505db">▸</span>Acteurs utilisés</h2><div class="yfold-content" id="content-a94505db" data-yfold-default="hide"><ul class="file-list"><li><a class="file caml_c" href="../Ada-S1/acteur-gada/gada-graphics.ads.html" data-eliom-c-onclick="1/LiiCFvIJDC">GAda.Graphics</a></li><li><a class="file caml_c" href="../Ada-S1/acteur-gada/gada-plus.ads.html" data-eliom-c-onclick="5Pw1SA0GnL4p">GAda.Plus</a></li><li><a class="file caml_c" href="acteur-jpg/jpg.ads.html" data-eliom-c-onclick="Xjd8iD5+DhdN">JPG</a></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('a94505db') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('3cc3bf0d')"><span class="arrow" id="arrow-3cc3bf0d">▸</span>Bilan</h2><div class="yfold-content" id="content-3cc3bf0d" data-yfold-default="hide"><ul class="success"><li>Vous connaissez la structure classique d'une image numérique : une matrice de point colorés (définis par trois composantes R,G,B).</li><li>Vous promettez d'être désormais rigoureux concernant les indices de lignes et de colonnes.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('3cc3bf0d') ;
|
||||
//]]>
|
||||
</script></section></main><footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="CHQs4AFxwlfS">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>
|
BIN
Y/Gen/Afficher_Image-1-597-.png
Normal file
BIN
Y/Gen/Afficher_Image-1-597-.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
Y/Gen/Afficher_Image-3-451-.png
Normal file
BIN
Y/Gen/Afficher_Image-3-451-.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
BIN
Y/Gen/Tester_Afficher_Image-0-c97-.png
Normal file
BIN
Y/Gen/Tester_Afficher_Image-0-c97-.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
Y/Images/image-4.png
Normal file
BIN
Y/Images/image-4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
BIN
Y/Images/image-decalee.png
Normal file
BIN
Y/Images/image-decalee.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
|
@ -1,4 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- Page generated by OCaml with Ocsigen.
|
||||
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>OCaml - Exam questions, 2020</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">OCaml - Exam questions, 2020</h1><nav><a class="caml_c" title="Back to main page" href="../ocaml.html" data-eliom-c-onclick="EQAb8IMjNUBO"></a></nav></div><main><ul class="lessons"><li><b>First assessment: </b><ul><li><a class="caml_c" href="exam2020/Sujet-1/enonce.txt.html" data-eliom-c-onclick="pLIrMVdGCFRZ">enonce.txt</a></li><li><a class="caml_c" href="exam2020/Sujet-2/types_filter.ml.html" data-eliom-c-onclick="TGe9/BOactAo">types_filter.ml</a></li><li><a class="caml_c" href="exam2020/Sujet-2/types_tree.ml.html" data-eliom-c-onclick="zs7l8RHkup2v">types_tree.ml</a></li><li><a class="caml_c" href="exam2020/Sujet-1/answers.ml.html" data-eliom-c-onclick="BwKcwJBuYPHs">answers.ml</a></li></ul><small class="pcom">If you wish to try by yourself on INSA computers, you will need to download these files: <a class="caml_c" href="exam2020/Sujet-1/qqs.ml" data-eliom-c-onclick="cb/6FIisg0rQ">qqs.ml</a> and <a class="caml_c" href="exam2020/Sujet-1/exam.ml" data-eliom-c-onclick="OpooB8i2quTR">exam.ml</a>. </small></li><li><b>Second assessment: </b><ul><li><a class="caml_c" href="exam2020/Sujet-2/enonce.txt.html" data-eliom-c-onclick="ifJ6ecGW6phB">enonce.txt</a></li><li><a class="caml_c" href="exam2020/Sujet-2/types_filter.ml.html" data-eliom-c-onclick="uM9kqWn5bf1u">types_filter.ml</a></li><li><a class="caml_c" href="exam2020/Sujet-2/types_tree.ml.html" data-eliom-c-onclick="OVsXl4WY3EfW">types_tree.ml</a></li><li><a class="caml_c" href="exam2020/Sujet-2/answers.ml.html" data-eliom-c-onclick="HXYon1ZrR6mr">answers.ml</a></li></ul><small class="pcom">On INSA computers, you will need <a class="caml_c" href="exam2020/Sujet-2/qqs.ml" data-eliom-c-onclick="3Fz/YOScsfOu">qqs.ml</a> and <a class="caml_c" href="exam2020/Sujet-2/exam.ml" data-eliom-c-onclick="PJgPgOKQP35N">exam.ml</a>. </small></li></ul>Note: there exist many possible solutions to each question.</main><footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="MgoO1NfRLEo0">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>
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<title>OCaml - Exam questions, 2020</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">OCaml - Exam questions, 2020</h1>
|
||||
<nav><a class="caml_c" title="Back to main page" href="../ocaml.html" data-eliom-c-onclick="EQAb8IMjNUBO"></a></nav>
|
||||
</div>
|
||||
<main>
|
||||
<ul class="lessons">
|
||||
<li><b>First assessment: </b>
|
||||
<ul>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-1/enonce.txt.html" data-eliom-c-onclick="pLIrMVdGCFRZ">enonce.txt</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/types_filter.ml.html" data-eliom-c-onclick="TGe9/BOactAo">types_filter.ml</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/types_tree.ml.html" data-eliom-c-onclick="zs7l8RHkup2v">types_tree.ml</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-1/answers.ml.html" data-eliom-c-onclick="BwKcwJBuYPHs">answers.ml</a></li>
|
||||
</ul><small class="pcom">If you wish to try by yourself on INSA computers, you will need to download these files: <a class="caml_c" href="exam2020/Sujet-1/qqs.ml" data-eliom-c-onclick="cb/6FIisg0rQ">qqs.ml</a> and <a class="caml_c"
|
||||
href="exam2020/Sujet-1/exam.ml" data-eliom-c-onclick="OpooB8i2quTR">exam.ml</a>. </small>
|
||||
</li>
|
||||
<li><b>Second assessment: </b>
|
||||
<ul>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/enonce.txt.html" data-eliom-c-onclick="ifJ6ecGW6phB">enonce.txt</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/types_filter.ml.html" data-eliom-c-onclick="uM9kqWn5bf1u">types_filter.ml</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/types_tree.ml.html" data-eliom-c-onclick="OVsXl4WY3EfW">types_tree.ml</a></li>
|
||||
<li><a class="caml_c" href="exam2020/Sujet-2/answers.ml.html" data-eliom-c-onclick="HXYon1ZrR6mr">answers.ml</a></li>
|
||||
</ul><small class="pcom">On INSA computers, you will need <a class="caml_c" href="exam2020/Sujet-2/qqs.ml" data-eliom-c-onclick="3Fz/YOScsfOu">qqs.ml</a> and <a class="caml_c" href="exam2020/Sujet-2/exam.ml"
|
||||
data-eliom-c-onclick="PJgPgOKQP35N">exam.ml</a>. </small>
|
||||
</li>
|
||||
</ul>Note: there exist many possible solutions to each question.
|
||||
</main>
|
||||
<footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="MgoO1NfRLEo0">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>
|
||||
|
|
|
@ -1,61 +1,243 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- Page generated by OCaml with Ocsigen.
|
||||
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>OCaml - mini project</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">OCaml - mini project</h1><nav><a class="caml_c" title="Back to main page" href="../ocaml.html" data-eliom-c-onclick="bOmVzvczyxF3"></a></nav></div><main><section class="yfold"><h3 class="yfold-title" onclick="toggleYfold('8a36b6ec')"><span class="arrow" id="arrow-8a36b6ec">▸</span>Setup and compilation</h3><div class="yfold-content" id="content-8a36b6ec" data-yfold-default="hide"><ul class="steps"><li>To begin with, create a directory for this project.</li><li>In order to save time, a few modules have already been written. <br/>Download these files <small class="pcom">(save link target as...)</small>: <span class="file"><a class="caml_c" href="project-files/graph.mli" data-eliom-c-onclick="0uSqfBGDN549">graph.mli</a></span>, <span class="file"><a class="caml_c" href="project-files/graph.ml" data-eliom-c-onclick="AkPsJ43v5R2W">graph.ml</a></span>, <span class="file"><a class="caml_c" href="project-files/gfile.mli" data-eliom-c-onclick="BcpQIw927mux">gfile.mli</a></span>, <span class="file"><a class="caml_c" href="project-files/gfile.ml" data-eliom-c-onclick="irnXIzp0LvLL">gfile.ml</a></span>, <span class="file"><a class="caml_c" href="project-files/ftest.ml" data-eliom-c-onclick="PBCKLM+8oRx9">ftest.ml</a></span>. <br/>We will explain these files soon.</li><li>Since you like downloading stuff, you may also save these files: <span class="file"><a class="caml_c" href="project-files/graph1" data-eliom-c-onclick="o8X2TiD3cChj">graph1</a></span>, <span class="file"><a class="caml_c" href="project-files/graph1.svg" data-eliom-c-onclick="uca+xD0CCdCZ">graph1.svg</a></span>. </li><li>The main file is <span class="hfile">ftest.ml</span> so, we try to compile it, as taught in lesson 6: <br/><code class="command">ocamlc -o ftest ftest.ml</code><small class="pcom">(try it) </small><code class="inline">-o ftest</code> indicates the name of the executable.<br/><samp class="errmsg">Error: Unbound module Gfile</samp></li><li>Look at the beginning of <span class="file">ftest.ml</span>: we open a module <code class="inline">Gfile</code>. <br/>Lesson learnt: <q>The modules used by the program must be compiled <b>before</b> the program.</q></li><li><code class="command">ocamlc -c graph.ml gfile.ml</code><code class="inline">-c</code> means compile only, no executable is built.<br/><samp class="errmsg">Error: Could not find the .cmi file for interface graph.mli</samp></li><li>A file named <span class="file">graph.mli</span> exists. It is the <b>interface</b> of module <code class="block"><span class="uident">Graph</span>
|
||||
</code><br/>Lesson learnt: <q>foo.mli must be compiled <b>before</b> foo.ml.</q></li><li><code class="command">ocamlc -c graph.mli graph.ml gfile.mli gfile.ml</code><br/><small class="pcom">something works, at last.</small></li><li>See which files have been produced: <code class="command">ls -l</code><small class="pcom"> (or more professionally, ls -alhv)</small><br/><div class="examples"><div class="example"><h5>Compilation of C files</h5><table><tr><td class="col1"><span class="hfile">file.c</span></td><td class="col2"> compiled into </td><td class="col3"><span class="hfile">file.o</span></td><td class="col4"><small class="pcom"> (by gcc)</small></td></tr></table></div><div class="example"><h5>Compilation of OCaml files</h5><table><tr><td class="col1"><span class="hfile">file.ml</span></td><td class="col2"> compiled into </td><td class="col3"><span class="hfile">file.cmo</span></td><td class="col4"><small class="pcom"> (by ocamlc)</small></td></tr><tr><td class="col1"><span class="hfile">file.mli</span></td><td class="col2"> compiled into </td><td class="col3"><span class="hfile">file.cmi</span></td><td class="col4"><small class="pcom"> (by ocamlc)</small></td></tr></table></div></div></li><li><code class="command">ocamlc -o ftest ftest.ml</code><br/><samp class="errmsg">Error: Required module `Gfile' is unavailable</samp></li><li>This error does not come from the <i>compiler</i> but from the <i>linker</i>. <br/>Lesson learnt: <q>When linking (building an executable), the modules must be explicitly given.</q></li><li><code class="command">ocamlc -o ftest graph.cmo gfile.cmo ftest.ml</code><br/>Note: <q>When linking, the modules must be explicitly given <b> in the order of dependencies.</b></q></li><li>You have obtained an executable <span class="file">ftest</span>. </li><li><code class="command">./ftest</code><small class="pcom"> (You get a usage message.)</small></li><li>Whenever you modify a file, you will have to recompile it as well as <b>all</b> the files that depend on it.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('8a36b6ec') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h3 class="yfold-title" onclick="toggleYfold('9588387f')"><span class="arrow" id="arrow-9588387f">▸</span>A few more things about compilation</h3><div class="yfold-content" id="content-9588387f" data-yfold-default="hide"><ul class="steps"><li>Recompiling everything is boring. This is why tools such as <a target="_blank" href="https://www.gnu.org/software/make/manual/html_node/index.html">GNU make</a><small class="pcom"> (for almost everything)</small> or <a target="_blank" href="https://www.tutorialspoint.com/ant/index.htm">ant</a><small class="pcom"> (for Java) </small> exist. <small class="pcom">Actually, the java compiler already takes care of dependencies.</small></li><li>A couple of build tools exist for OCaml too. Let us give a try to <b>ocamlbuild</b>. </li><li>First, remove all the compilation files: <code class="command">rm -f *.cmi *.cmo ftest</code><small class="pcom">(In order to avoid confusion between tools, ocamlbuild refuses to work if it finds compiled files.)</small></li><li>Use <code class="command">ocamlbuild ftest.byte</code> to build the bytecode executable, or <code class="command">ocamlbuild ftest.native</code> to build the native executable. (You need only one of them).<br/><small class="pcom">In case you ask, the compiled files can be found in a directory named <span class="file">_build</span>. </small></li><li><code class="command">./ftest.byte</code> or <code class="command">./ftest.native</code><small class="pcom">(still prints a usage message, though).</small></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('9588387f') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h3 class="yfold-title" onclick="toggleYfold('14504082')"><span class="arrow" id="arrow-14504082">▸</span>Discover the project modules</h3><div class="yfold-content" id="content-14504082" data-yfold-default="hide"><ul class="steps"><li>You cannot compile the project using ocaml-top. Use any text editor instead, e.g. <code class="command">emacs</code><small class="pcom"> (configured as explained at the beginning of <a class="caml_c" href="sujet6.html" data-eliom-c-onclick="X4YxKfFrPGLk">OCaml - Lesson 6</a>) </small> or visual studio code, if you know how to launch it.<br/>You may enjoy A. Bit-Monnot's setup <b>configuration for VSCode</b> : <a target="_blank" href="https://github.com/arthur-bit-monnot/ocaml-maxflow-project">ocaml-maxflow-project on github</a>. </li><li>The base project contains two modules and a main program:<ul><li><span class="file">graph.mli</span> and <span class="file">graph.ml</span> which define a module <code class="block"><span class="uident">Graph</span>
|
||||
</code></li><li><span class="file">gfile.mli</span> and <span class="file">gfile.ml</span> which define a module <code class="block"><span class="uident">Gfile</span>
|
||||
</code></li><li><span class="file">ftest.ml</span>, the main program.</li></ul></li><li>Look at the interfaces of <code class="block"><span class="uident">Graph</span>
|
||||
</code>(<span class="file">graph.mli</span>) and <code class="block"><span class="uident">Gfile</span>
|
||||
</code><br/>All functions are already implemented in <span class="file">graph.ml</span> and <span class="file">gfile.ml</span><br/><b>You must not modify the module <code class="block"><span class="uident">Graph</span>
|
||||
</code></b>, but you will have to create new modules and to modify Gfile. </li><li>Try to understand the graph file format (look at the example <span class="file">graph1</span> and read quickly gfile.ml)</li><li>To ease the writing of algorithms, write a new module <code class="block"><span class="uident">Tools</span>
|
||||
</code>, with the following signature <small class="pcom">(the signature must be in file tools.mli)</small> :<br/><div class="examples"><div class="example"><h5>Interface file</h5><code class="block"><span class="kw">open</span> <span class="uident">Graph</span>
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<span class="kw">val</span> clone_nodes: 'a graph -> 'b graph
|
||||
<span class="kw">val</span> gmap: 'a graph -> ('a -> 'b) -> 'b graph
|
||||
<span class="kw">val</span> add_arc: int graph -> id -> id -> int -> int graph
|
||||
</code></div><div class="example"><h5>Implementation file</h5><code class="block"><span class="comment">(* Yes, we have to repeat open Graph. *)</span>
|
||||
<span class="kw">open</span> <span class="uident">Graph</span>
|
||||
<head>
|
||||
<title>OCaml - mini project</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>
|
||||
|
||||
<span class="comment">(* assert false is of type ∀α.α, so the type-checker is happy. *)</span>
|
||||
<span class="kw">let</span> <span class="letvar">clone_nodes</span> gr = <span class="kw">assert</span> <span class="kw">false</span>
|
||||
<span class="kw">let</span> <span class="letvar">gmap</span> gr f = <span class="kw">assert</span> <span class="kw">false</span>
|
||||
...
|
||||
</code></div></div><ul><li><code class="block">clone_nodes gr
|
||||
</code> returns a new graph having the same nodes than gr, but no arc.<small class="pcom"> (code : one line)</small><br/>In order to find your errors more quickly, you may add an annotation : <code class="block"><span class="kw">let</span> <span class="letvar">clone_nodes</span> (gr:'a graph) = ...
|
||||
</code></li><li><code class="block">gmap gr f
|
||||
</code> maps all arcs of gr by function f.<small class="pcom"> (⩽3 lines)</small></li><li><code class="block">add_arc g id1 id2 n
|
||||
</code> adds n to the value of the arc between id1 and id2. If the arc does not exist, it is created.</li></ul></li><li>In order to test, you may use an <a target="_blank" href="https://www-m9.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html">online graph editor</a><span class="menu"> (Create a graph)</span>, and download your graphs.</li><li>In order to visualize graphs, we will use the famous <a target="_blank" href="http://www.graphviz.org/">Graphviz library</a>. <br/>Write a new function <code class="block">export
|
||||
</code> in <code class="block"><span class="uident">Gfile</span>
|
||||
</code> which writes a string graph in dot format (the format understood by graphviz). To understand the expected format, you just have to look at <a target="_blank" href="https://graphviz.gitlab.io/_pages/Gallery/directed/fsm.html">this example</a><small class="pcom"> (click on the picture to get the source file)</small>. <br/>To generate an image from a dot file, you can use: <br/><code class="command">dot -Tsvg your-dot-file > some-output-file.svg</code></li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('14504082') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h3 class="yfold-title" onclick="toggleYfold('41d55fee')"><span class="arrow" id="arrow-41d55fee">▸</span>To be done</h3><div class="yfold-content" id="content-41d55fee" data-yfold-default="hide"><ul class="steps"><li><b>Minimal acceptable project: </b>you should at least implement the Ford-Fulkerson algorithm (in a separate module) and test it on several examples. <ul><li>You all remember the <a target="_blank" href="https://homepages.laas.fr/huguet/drupal/content/enseignement-3mic"> 3 MIC lecture on Graphs</a> by Marie-Jo Huguet.</li><li><a target="_blank" href="https://www-m9.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html">An interactive presentation of the algorithm</a>. </li><li>A<a target="_blank" href="https://www-npa.lip6.fr/blin/enseignements/"> french presentation of flow problems</a> (see "Algorithmes des graphes / Flots"). </li></ul></li><li><b>Medium project: </b>find a use-case of this algorithm (e.g. network transportation, bandwidth, or bipartite matching) and write a program that solves the problem, given input files easier to write than graph files. <ul><li><a target="_blank" href="https://hackernoon.com/max-flow-algorithm-in-real-life-551ebd781b25">An example with money sharing.</a></li><li>Wikipedia offers several examples on its <a target="_blank" href="https://en.wikipedia.org/wiki/Maximum_flow_problem">max flow page</a>. </li><li><a target="_blank" href="https://medium.com/swlh/real-world-network-flow-cricket-elimination-problem-55a3036a5d60">The cricket elimination problem</a></li><li><a target="_blank" href="https://www.anishathalye.com/2015/09/24/algorithms-in-the-real-world-host-matching/">Finding where guests will sleep.</a></li><li><a target="_blank" href="https://www.geeksforgeeks.org/maximum-bipartite-matching/">Bipartite matching</a></li><li><a target="_blank" href="http://www.cs.toronto.edu/~sven/Papers/bipartite.pdf">Object recognition through bipartite matching</a></li></ul></li><li><b>Better project: </b>enhance the medium project by taking into account other constraints - and implementing the max-flow min-cost algorithm.<br/>As an example, your program could be used to match a set of people to a set of ressources (e.g. students to <i>projets tutorés</i>, or future students to universites as in late APB) taking into account people's preferences. Your system should be as fair as possible and avoid biases.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('41d55fee') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h3 class="yfold-title" onclick="toggleYfold('ee09a9ff')"><span class="arrow" id="arrow-ee09a9ff">▸</span>Some technical support</h3><div class="yfold-content" id="content-ee09a9ff" data-yfold-default="hide"><h4>Debugging</h4>In order to activate debugging: <ul class="steps"><li>You must create a file named <span class="hfile">_tags</span> in your project directory (this file is read by ocamlbuild).<br/>Add the following line: <pre>true: debug</pre></li><li>In the terminal, set the variable <var>OCAMLRUNPARAM</var> to <var>b</var><small class="pcom"> (means: backtrace)</small><br/><code class="command">export OCAMLRUNPARAM="b"</code>then, you can launch your program.</li></ul><h4>Packages</h4><ul><li>If you use special modules, such as <var>Unix</var><small class="pcom"> (package name: unix)</small> or <var>Graphics</var><small class="pcom"> (package name: graphics)</small>, you need to tell ocamlbuild to use the corresponding package. In the file <span class="hfile">_tags</span>, add the following line: <pre>true: package(unix)</pre> or <pre>true: package(unix,graphics,...)</pre></li><li>In order to build, you have to use:<code class="command">ocamlbuild -use-ocamlfind myprog.native</code><br class="bbr"/><b>ocamlfind</b> (findlib) is a tool written by a prolific OCaml developper: <a target="_blank" href="http://www.gerd-stolpmann.de/buero/freie_sw_beitraege.html.en">Gerd Stolpmann</a>. It is a library manager for OCaml.</li></ul><h4>How to start writing the Ford-Fulkerson algorithm (alert: SPOILER)</h4><p>If you are stuck, you may start by writing a function which finds a path in a graph:</p><code class="block">
|
||||
<span class="comment">(* A path is a list of nodes. *)</span>
|
||||
<span class="kw">type</span> path = id list
|
||||
<body>
|
||||
<div class="header" id="header">
|
||||
<h1 id="title">OCaml - mini project</h1>
|
||||
<nav><a class="caml_c" title="Back to main page" href="../ocaml.html" data-eliom-c-onclick="bOmVzvczyxF3"></a></nav>
|
||||
</div>
|
||||
<main>
|
||||
<section class="yfold">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('8a36b6ec')"><span class="arrow" id="arrow-8a36b6ec">▸</span>Setup and compilation</h3>
|
||||
<div class="yfold-content" id="content-8a36b6ec" data-yfold-default="hide">
|
||||
<ul class="steps">
|
||||
<li>To begin with, create a directory for this project.</li>
|
||||
<li>In order to save time, a few modules have already been written. <br />Download these files <small class="pcom">(save link target as...)</small>: <span class="file"><a class="caml_c" href="project-files/graph.mli"
|
||||
data-eliom-c-onclick="0uSqfBGDN549">graph.mli</a></span>, <span class="file"><a class="caml_c" href="project-files/graph.ml" data-eliom-c-onclick="AkPsJ43v5R2W">graph.ml</a></span>, <span class="file"><a class="caml_c"
|
||||
href="project-files/gfile.mli" data-eliom-c-onclick="BcpQIw927mux">gfile.mli</a></span>, <span class="file"><a class="caml_c" href="project-files/gfile.ml" data-eliom-c-onclick="irnXIzp0LvLL">gfile.ml</a></span>, <span class="file"><a
|
||||
class="caml_c" href="project-files/ftest.ml" data-eliom-c-onclick="PBCKLM+8oRx9">ftest.ml</a></span>. <br />We will explain these files soon.</li>
|
||||
<li>Since you like downloading stuff, you may also save these files: <span class="file"><a class="caml_c" href="project-files/graph1" data-eliom-c-onclick="o8X2TiD3cChj">graph1</a></span>, <span class="file"><a class="caml_c"
|
||||
href="project-files/graph1.svg" data-eliom-c-onclick="uca+xD0CCdCZ">graph1.svg</a></span>. </li>
|
||||
<li>The main file is <span class="hfile">ftest.ml</span> so, we try to compile it, as taught in lesson 6: <br /><code class="command">ocamlc -o ftest ftest.ml</code><small class="pcom">(try it) </small><code class="inline">-o ftest</code>
|
||||
indicates the name of the executable.<br /><samp class="errmsg">Error: Unbound module Gfile</samp></li>
|
||||
<li>Look at the beginning of <span class="file">ftest.ml</span>: we open a module <code class="inline">Gfile</code>. <br />Lesson learnt: <q>The modules used by the program must be compiled <b>before</b> the program.</q></li>
|
||||
<li><code class="command">ocamlc -c graph.ml gfile.ml</code><code class="inline">-c</code> means compile only, no executable is built.<br /><samp class="errmsg">Error: Could not find the .cmi file for interface graph.mli</samp></li>
|
||||
<li>A file named <span class="file">graph.mli</span> exists. It is the <b>interface</b> of module <code class="block"><span class="uident">Graph</span>
|
||||
</code><br />Lesson learnt: <q>foo.mli must be compiled <b>before</b> foo.ml.</q></li>
|
||||
<li><code class="command">ocamlc -c graph.mli graph.ml gfile.mli gfile.ml</code><br /><small class="pcom">something works, at last.</small></li>
|
||||
<li>See which files have been produced: <code class="command">ls -l</code><small class="pcom"> (or more professionally, ls -alhv)</small><br />
|
||||
<div class="examples">
|
||||
<div class="example">
|
||||
<h5>Compilation of C files</h5>
|
||||
<table>
|
||||
<tr>
|
||||
<td class="col1"><span class="hfile">file.c</span></td>
|
||||
<td class="col2"> compiled into </td>
|
||||
<td class="col3"><span class="hfile">file.o</span></td>
|
||||
<td class="col4"><small class="pcom"> (by gcc)</small></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="example">
|
||||
<h5>Compilation of OCaml files</h5>
|
||||
<table>
|
||||
<tr>
|
||||
<td class="col1"><span class="hfile">file.ml</span></td>
|
||||
<td class="col2"> compiled into </td>
|
||||
<td class="col3"><span class="hfile">file.cmo</span></td>
|
||||
<td class="col4"><small class="pcom"> (by ocamlc)</small></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="col1"><span class="hfile">file.mli</span></td>
|
||||
<td class="col2"> compiled into </td>
|
||||
<td class="col3"><span class="hfile">file.cmi</span></td>
|
||||
<td class="col4"><small class="pcom"> (by ocamlc)</small></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li><code class="command">ocamlc -o ftest ftest.ml</code><br /><samp class="errmsg">Error: Required module `Gfile' is unavailable</samp></li>
|
||||
<li>This error does not come from the <i>compiler</i> but from the <i>linker</i>. <br />Lesson learnt: <q>When linking (building an executable), the modules must be explicitly given.</q></li>
|
||||
<li><code class="command">ocamlc -o ftest graph.cmo gfile.cmo ftest.ml</code><br />Note: <q>When linking, the modules must be explicitly given <b> in the order of dependencies.</b></q></li>
|
||||
<li>You have obtained an executable <span class="file">ftest</span>. </li>
|
||||
<li><code class="command">./ftest</code><small class="pcom"> (You get a usage message.)</small></li>
|
||||
<li>Whenever you modify a file, you will have to recompile it as well as <b>all</b> the files that depend on it.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('8a36b6ec');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('9588387f')"><span class="arrow" id="arrow-9588387f">▸</span>A few more things about compilation</h3>
|
||||
<div class="yfold-content" id="content-9588387f" data-yfold-default="hide">
|
||||
<ul class="steps">
|
||||
<li>Recompiling everything is boring. This is why tools such as <a target="_blank" href="https://www.gnu.org/software/make/manual/html_node/index.html">GNU make</a><small class="pcom"> (for almost everything)</small> or <a target="_blank"
|
||||
href="https://www.tutorialspoint.com/ant/index.htm">ant</a><small class="pcom"> (for Java) </small> exist. <small class="pcom">Actually, the java compiler already takes care of dependencies.</small></li>
|
||||
<li>A couple of build tools exist for OCaml too. Let us give a try to <b>ocamlbuild</b>. </li>
|
||||
<li>First, remove all the compilation files: <code class="command">rm -f *.cmi *.cmo ftest</code><small class="pcom">(In order to avoid confusion between tools, ocamlbuild refuses to work if it finds compiled files.)</small></li>
|
||||
<li>Use <code class="command">ocamlbuild ftest.byte</code> to build the bytecode executable, or <code class="command">ocamlbuild ftest.native</code> to build the native executable. (You need only one of them).<br /><small class="pcom">In
|
||||
case you ask, the compiled files can be found in a directory named <span class="file">_build</span>. </small></li>
|
||||
<li><code class="command">./ftest.byte</code> or <code class="command">./ftest.native</code><small class="pcom">(still prints a usage message, though).</small></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('9588387f');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('14504082')"><span class="arrow" id="arrow-14504082">▸</span>Discover the project modules</h3>
|
||||
<div class="yfold-content" id="content-14504082" data-yfold-default="hide">
|
||||
<ul class="steps">
|
||||
<li>You cannot compile the project using ocaml-top. Use any text editor instead, e.g. <code class="command">emacs</code><small class="pcom"> (configured as explained at the beginning of <a class="caml_c" href="sujet6.html"
|
||||
data-eliom-c-onclick="X4YxKfFrPGLk">OCaml - Lesson 6</a>) </small> or visual studio code, if you know how to launch it.<br />You may enjoy A. Bit-Monnot's setup <b>configuration for VSCode</b> : <a target="_blank"
|
||||
href="https://github.com/arthur-bit-monnot/ocaml-maxflow-project">ocaml-maxflow-project on github</a>. </li>
|
||||
<li>The base project contains two modules and a main program:<ul>
|
||||
<li><span class="file">graph.mli</span> and <span class="file">graph.ml</span> which define a module <code class="block"><span class="uident">Graph</span>
|
||||
</code></li>
|
||||
<li><span class="file">gfile.mli</span> and <span class="file">gfile.ml</span> which define a module <code class="block"><span class="uident">Gfile</span>
|
||||
</code></li>
|
||||
<li><span class="file">ftest.ml</span>, the main program.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Look at the interfaces of <code class="block"><span class="uident">Graph</span>
|
||||
</code>(<span class="file">graph.mli</span>) and <code class="block"><span class="uident">Gfile</span>
|
||||
</code><br />All functions are already implemented in <span class="file">graph.ml</span> and <span class="file">gfile.ml</span><br /><b>You must not modify the module <code class="block"><span class="uident">Graph</span>
|
||||
</code></b>, but you will have to create new modules and to modify Gfile. </li>
|
||||
<li>Try to understand the graph file format (look at the example <span class="file">graph1</span> and read quickly gfile.ml)</li>
|
||||
<li>To ease the writing of algorithms, write a new module <code class="block"><span class="uident">Tools</span>
|
||||
</code>, with the following signature <small class="pcom">(the signature must be in file tools.mli)</small> :<br />
|
||||
<div class="examples">
|
||||
<div class="example">
|
||||
<h5>Interface file</h5><code class="block"><span class="kw">open</span> <span class="uident">Graph</span>
|
||||
|
||||
<span class="comment">(* find_path gr forbidden id1 id2
|
||||
* returns None if no path can be found.
|
||||
* returns Some p if a path p from id1 to id2 has been found.
|
||||
*
|
||||
* forbidden is a list of forbidden nodes (they have already been visited)
|
||||
*)</span>
|
||||
find_path: int graph -> id list -> id -> id -> path option
|
||||
<span class="kw">val</span> clone_nodes: 'a graph -> 'b graph
|
||||
<span class="kw">val</span> gmap: 'a graph -> ('a -> 'b) -> 'b graph
|
||||
<span class="kw">val</span> add_arc: int graph -> id -> id -> int -> int graph
|
||||
</code>
|
||||
</div>
|
||||
<div class="example">
|
||||
<h5>Implementation file</h5><code class="block"><span class="comment">(* Yes, we have to repeat open Graph. *)</span>
|
||||
<span class="kw">open</span> <span class="uident">Graph</span>
|
||||
|
||||
</code></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('ee09a9ff') ;
|
||||
//]]>
|
||||
</script></section></main><footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="QkmB87Beytxc">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>
|
||||
<span class="comment">(* assert false is of type ∀α.α, so the type-checker is happy. *)</span>
|
||||
<span class="kw">let</span> <span class="letvar">clone_nodes</span> gr = <span class="kw">assert</span> <span class="kw">false</span>
|
||||
<span class="kw">let</span> <span class="letvar">gmap</span> gr f = <span class="kw">assert</span> <span class="kw">false</span>
|
||||
...
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
<ul>
|
||||
<li><code class="block">clone_nodes gr
|
||||
</code> returns a new graph having the same nodes than gr, but no arc.<small class="pcom"> (code : one line)</small><br />In order to find your errors more quickly, you may add an annotation : <code class="block"><span
|
||||
class="kw">let</span> <span class="letvar">clone_nodes</span> (gr:'a graph) = ...
|
||||
</code></li>
|
||||
<li><code class="block">gmap gr f
|
||||
</code> maps all arcs of gr by function f.<small class="pcom"> (⩽3 lines)</small></li>
|
||||
<li><code class="block">add_arc g id1 id2 n
|
||||
</code> adds n to the value of the arc between id1 and id2. If the arc does not exist, it is created.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>In order to test, you may use an <a target="_blank" href="https://www-m9.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html">online graph editor</a><span class="menu"> (Create a graph)</span>, and download your graphs.</li>
|
||||
<li>In order to visualize graphs, we will use the famous <a target="_blank" href="http://www.graphviz.org/">Graphviz library</a>. <br />Write a new function <code class="block">export
|
||||
</code> in <code class="block"><span class="uident">Gfile</span>
|
||||
</code> which writes a string graph in dot format (the format understood by graphviz). To understand the expected format, you just have to look at <a target="_blank" href="https://graphviz.gitlab.io/_pages/Gallery/directed/fsm.html">this
|
||||
example</a><small class="pcom"> (click on the picture to get the source file)</small>. <br />To generate an image from a dot file, you can use: <br /><code class="command">dot -Tsvg your-dot-file > some-output-file.svg</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('14504082');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('41d55fee')"><span class="arrow" id="arrow-41d55fee">▸</span>To be done</h3>
|
||||
<div class="yfold-content" id="content-41d55fee" data-yfold-default="hide">
|
||||
<ul class="steps">
|
||||
<li><b>Minimal acceptable project: </b>you should at least implement the Ford-Fulkerson algorithm (in a separate module) and test it on several examples. <ul>
|
||||
<li>You all remember the <a target="_blank" href="https://homepages.laas.fr/huguet/drupal/content/enseignement-3mic"> 3 MIC lecture on Graphs</a> by Marie-Jo Huguet.</li>
|
||||
<li><a target="_blank" href="https://www-m9.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html">An interactive presentation of the algorithm</a>. </li>
|
||||
<li>A<a target="_blank" href="https://www-npa.lip6.fr/blin/enseignements/"> french presentation of flow problems</a> (see "Algorithmes des graphes / Flots"). </li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><b>Medium project: </b>find a use-case of this algorithm (e.g. network transportation, bandwidth, or bipartite matching) and write a program that solves the problem, given input files easier to write than graph files. <ul>
|
||||
<li><a target="_blank" href="https://hackernoon.com/max-flow-algorithm-in-real-life-551ebd781b25">An example with money sharing.</a></li>
|
||||
<li>Wikipedia offers several examples on its <a target="_blank" href="https://en.wikipedia.org/wiki/Maximum_flow_problem">max flow page</a>. </li>
|
||||
<li><a target="_blank" href="https://medium.com/swlh/real-world-network-flow-cricket-elimination-problem-55a3036a5d60">The cricket elimination problem</a></li>
|
||||
<li><a target="_blank" href="https://www.anishathalye.com/2015/09/24/algorithms-in-the-real-world-host-matching/">Finding where guests will sleep.</a></li>
|
||||
<li><a target="_blank" href="https://www.geeksforgeeks.org/maximum-bipartite-matching/">Bipartite matching</a></li>
|
||||
<li><a target="_blank" href="http://www.cs.toronto.edu/~sven/Papers/bipartite.pdf">Object recognition through bipartite matching</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><b>Better project: </b>enhance the medium project by taking into account other constraints - and implementing the max-flow min-cost algorithm.<br />As an example, your program could be used to match a set of people to a set of
|
||||
ressources (e.g. students to <i>projets tutorés</i>, or future students to universites as in late APB) taking into account people's preferences. Your system should be as fair as possible and avoid biases.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('41d55fee');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('ee09a9ff')"><span class="arrow" id="arrow-ee09a9ff">▸</span>Some technical support</h3>
|
||||
<div class="yfold-content" id="content-ee09a9ff" data-yfold-default="hide">
|
||||
<h4>Debugging</h4>In order to activate debugging: <ul class="steps">
|
||||
<li>You must create a file named <span class="hfile">_tags</span> in your project directory (this file is read by ocamlbuild).<br />Add the following line:
|
||||
<pre>true: debug</pre>
|
||||
</li>
|
||||
<li>In the terminal, set the variable <var>OCAMLRUNPARAM</var> to <var>b</var><small class="pcom"> (means: backtrace)</small><br /><code class="command">export OCAMLRUNPARAM="b"</code>then, you can launch your program.</li>
|
||||
</ul>
|
||||
<h4>Packages</h4>
|
||||
<ul>
|
||||
<li>If you use special modules, such as <var>Unix</var><small class="pcom"> (package name: unix)</small> or <var>Graphics</var><small class="pcom"> (package name: graphics)</small>, you need to tell ocamlbuild to use the corresponding
|
||||
package. In the file <span class="hfile">_tags</span>, add the following line:
|
||||
<pre>true: package(unix)</pre> or
|
||||
<pre>true: package(unix,graphics,...)</pre>
|
||||
</li>
|
||||
<li>In order to build, you have to use:<code class="command">ocamlbuild -use-ocamlfind myprog.native</code><br class="bbr" /><b>ocamlfind</b> (findlib) is a tool written by a prolific OCaml developper: <a target="_blank"
|
||||
href="http://www.gerd-stolpmann.de/buero/freie_sw_beitraege.html.en">Gerd Stolpmann</a>. It is a library manager for OCaml.</li>
|
||||
</ul>
|
||||
<h4>How to start writing the Ford-Fulkerson algorithm (alert: SPOILER)</h4>
|
||||
<p>If you are stuck, you may start by writing a function which finds a path in a graph:</p><code class="block">
|
||||
<span class="comment">(* A path is a list of nodes. *)</span>
|
||||
<span class="kw">type</span> path = id list
|
||||
|
||||
<span class="comment">(* find_path gr forbidden id1 id2
|
||||
* returns None if no path can be found.
|
||||
* returns Some p if a path p from id1 to id2 has been found.
|
||||
*
|
||||
* forbidden is a list of forbidden nodes (they have already been visited)
|
||||
*)</span>
|
||||
find_path: int graph -> id list -> id -> id -> path option
|
||||
|
||||
</code>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('ee09a9ff');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
</main>
|
||||
<footer><small class="pcom"><a class="caml_c" href="../yversion.html" data-eliom-c-onclick="QkmB87Beytxc">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>
|
||||
|
|
335
Y/ocaml.html
335
Y/ocaml.html
|
@ -1,72 +1,277 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- Page generated by OCaml with Ocsigen.
|
||||
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>Functional programming in OCaml</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">Functional programming in OCaml</h1></div><main><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('f6c61644')"><span class="arrow" id="arrow-f6c61644">▸</span>Introduction</h2><div class="yfold-content flex" id="content-f6c61644" data-yfold-default="hide"><section class="debug flex2 card"><h3 class="debug">About the course</h3><p class="debug">Intended for functional beginners already familiar with some programming language.</p><h4 class="debug">Goals</h4><p class="debug">If all goes well, by the end of this course, you shall be able to:</p><ul class="debug success"><li>Understand <b class="debug">lambda-terms</b> and write <b class="debug">pure functional programs</b>. </li><li>Design <b class="debug">recursive functions</b> to iterate over recursive <b class="debug">data types</b>. </li><li>Wonder how you have survived so far without <b class="debug">algebraic data types</b> and <b class="debug">parameterized types</b>. </li><li>Think in terms of <b class="debug">higher-order functions</b> in order to write reusable code. </li><li>Astonish yourself by writing <b class="debug">polymorphic functions</b> without even noticing. </li></ul><h4 class="debug">Evaluation</h4><p class="debug">The exam is on october, 12th: a list of exercises, on computer.</p></section><section class="debug flex1 card"><h3 class="debug">Setup</h3><ul class="debug steps"><li>To use OCaml at INSA, copy to your homedir <span class="debug file">/mnt/commetud/GEI/OCaml/.profile</span> and <b class="debug">read it.</b></li><li>Open a new terminal and launch utop: <code class="debug command">utop</code><br class="debug vskip"/>You should get a nice greeting message. Press CTRL+D to quit.</li><li>Alternatively, you can write small OCaml programs directly on <a class="debug" target="_blank" href="https://try.ocamlpro.com/">Try OCaml</a>. </li></ul></section></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('f6c61644') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('bf745052')"><span class="arrow" id="arrow-bf745052">▸</span>Programming assignments (lessons)</h2><div class="yfold-content" id="content-bf745052" data-yfold-default="hide"><p>Each lesson must be worked <b>individually</b>, and completed before starting the next one.</p><aside class="answers"><h4>Answers</h4><ul><li>Lesson 1: <a class="caml_c" href="OCaml/all-answers/xkzb/lesson1.ml.html" data-eliom-c-onclick="1E4MGQOS9wC5">lesson1.ml</a></li><li>Lesson 2: <a class="caml_c" href="OCaml/all-answers/hitj/lesson2.ml.html" data-eliom-c-onclick="Grw/MZP+WPeg">lesson2.ml</a></li><li>Lesson 3: <a class="caml_c" href="OCaml/all-answers/lcdz/lesson3.ml.html" data-eliom-c-onclick="xypUTosu6RUM">lesson3.ml</a></li><li>Lesson 4: <a class="caml_c" href="OCaml/all-answers/pmyd/lesson4.ml.html" data-eliom-c-onclick="PCFy+czkv2Rs">lesson4.ml</a></li><li>Lesson 5: <a class="caml_c" href="OCaml/all-answers/fwiz/lesson5.ml.html" data-eliom-c-onclick="R4j/cMya1IJ+">lesson5.ml</a></li><li>Lesson 6: <a class="caml_c" href="OCaml/all-answers/dmug/lesson6.ml.html" data-eliom-c-onclick="vZsEvcolLYjP">lesson6.ml</a></li></ul><small class="pcom">Some solutions might be out of date, or unclear—<br/>signal them to Mr. Le Botlan, then.</small></aside><ul class="lessons"><li><a class="caml_c" href="OCaml/sujet1.html" data-eliom-c-onclick="a9t25dVDYCcf"><span class="lbutton">Lesson 1</span>The ocaml interpreter, ground types, built-in types.</a></li><li><a class="caml_c" href="OCaml/sujet2.html" data-eliom-c-onclick="v9VgLpqlyO9u"><span class="lbutton">Lesson 2</span>Functions, curryfication.</a></li><li><a class="caml_c" href="OCaml/sujet3.html" data-eliom-c-onclick="nVoR9pY+HmLK"><span class="lbutton">Lesson 3</span>Pattern matching, inner let.</a></li><li><a class="caml_c" href="OCaml/sujet4.html" data-eliom-c-onclick="x/OhOTSgZ4w2"><span class="lbutton">Lesson 4</span>Type structures.</a></li><li><a class="caml_c" href="OCaml/sujet5.html" data-eliom-c-onclick="B3smUwRNlwiX"><span class="lbutton">Lesson 5</span>Algorithms and more type structures</a></li><li><a class="caml_c" href="OCaml/sujet6.html" data-eliom-c-onclick="s69LFl2Iqlfj"><span class="lbutton">Lesson 6</span>Compilation, exceptions, side effects.</a></li></ul><br class="vskip"/><h4>For the curious, some complementary information</h4><ul><li><a target="_blank" href="https://reasonml.github.io/">Facebook's REASON</a>, or how to program in OCaml while pretending to write Javascript.</li><li>Xavier Leroy, proficient developper of the Ocaml compiler, tells <a target="_blank" href="http://gallium.inria.fr/blog/intel-skylake-bug/">how he ran into a bug in some Intel processors</a>. </li><li>Watch 👁<a target="_blank" href="https://youtu.be/-PX0BV9hGZY">Tail-call recursion, the musical</a>, which explains how call-stacks work.</li><li>Learn why OCaml's <a target="_blank" href="http://www.ocamlpro.com/2020/03/23/ocaml-new-best-fit-garbage-collector/">Garbage collector</a> is efficient.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('bf745052') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('39af12ce')"><span class="arrow" id="arrow-39af12ce">▸</span>Exam-type exercises</h2><div class="yfold-content" id="content-39af12ce" data-yfold-default="hide"><aside class="answers"><h4>Answers</h4><ul><li>Ex. 1: <a class="caml_c" href="OCaml/all-answers/cnkv/exo1.ml.html" data-eliom-c-onclick="34UoL/1d4mYp">exo1.ml</a></li><li>Ex. 2: <a class="caml_c" href="OCaml/all-answers/viuq/exo2.ml.html" data-eliom-c-onclick="pRryOPK+/Lta">exo2.ml</a></li><li>Ex. 3: <a class="caml_c" href="OCaml/all-answers/mfmd/exo3.ml.html" data-eliom-c-onclick="DaTtfOf8fMb5">exo3.ml</a></li></ul></aside><ul><li>Exam questions are only intended to test your skills. They are not intended to be smart or enlightening. Thus, do not get surprised if examples are totally unmeaningful.</li><li>You do not have to write tail-recursive functions, unless explicitly required.</li></ul><ul class="lessons"><li><a class="caml_c" href="OCaml/exercises1.html" data-eliom-c-onclick="/knwUQOtRXuQ"><span class="lbutton">Ex. 1</span>Basic types, curried functions, polymorphism, pattern matching</a></li><li><a class="caml_c" href="OCaml/exercises2.html" data-eliom-c-onclick="fQtG/3W6LzgO"><span class="lbutton">Ex. 2</span>Lists, records, variants.</a></li><li><a class="caml_c" href="OCaml/exercises3.html" data-eliom-c-onclick="xYhuiXiN7rkq"><span class="lbutton">Ex. 3</span>Recursive structures, exceptions</a></li><li><a target="_blank" href="https://ocaml.org/learn/tutorials/99problems.html"><span class="lbutton">Ex. 99</span>A list of 99 problems of various difficulty.</a><small class="pcom"> (Some of them are easier than the exam, some are harder.)</small></li><li><a class="caml_c" href="OCaml/exam-2017.html" data-eliom-c-onclick="gcIDKoTkIR6N"><span class="lbutton">Ex. 2017</span>Exam questions, 2017.</a></li><li><a class="caml_c" href="OCaml/exam-2019.html" data-eliom-c-onclick="bvximRdiy7/t"><span class="lbutton">Ex. 2019</span>Exam questions, 2019.</a></li><li><a class="caml_c" href="OCaml/exam-2020.html" data-eliom-c-onclick="wNGyeoaEg24S"><span class="lbutton">Ex. 2020</span>Exam questions, 2020.</a></li></ul><br class="vskip"/><h4 id="get-prepared">Get prepared for the exam:</h4><p>The following works only on INSA computers (purposely).</p><ul><li>You must have configured your account to use ocaml (see Setup above) </li><li>In a terminal, launch <code class="command">/mnt/commetud/GEI/run-exam &</code></li><li>Choose the <b>OCaml Test Exam</b>. The expected password is <kbd>exam</kbd></li><li>This test exam contains two easy questions.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('39af12ce') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('0836c5b9')"><span class="arrow" id="arrow-0836c5b9">▸</span>Project</h2><div class="yfold-content" id="content-0836c5b9" data-yfold-default="hide"><p>The project is to be done by pairs of students having the same level.</p><h4>Requirements</h4><p>➪ You have completed all the lessons, and know how to write <a target="_blank" href="https://ocaml.org/learn/tutorials/modules.html">OCaml Modules. </a></p><h4>How it goes</h4><ul class="steps"><li>The goal is to implement an algorithm computing the max-flow of a flow graph, using the Ford–Fulkerson algorithm, and optionally improve it to take into account other constraints (e.g. minimize cost).<br/>See the <a class="caml_c" href="OCaml/project.html" data-eliom-c-onclick="N1JNdzMrXJaN">details of the project</a>. </li><li>You are free to propose another project, by considering another graph algorithm — check with the teacher.</li></ul><h4>Evaluation</h4><ul><li>Before <b>december, 12th</b>, you have to send to your teacher (D. Le Botlan or A. Bit-Monnot) a link to your github project <small class="pcom">(or any other similar repository)</small>. </li><li>Manage to meet your teacher and show him a very quick demo (2 minutes). He will then ask you questions about your project (5-10 minutes).</li></ul>The final grade takes into account:<ul><li>your achievements (how much is in your project)</li><li>your code's modularity (do you use modules, abstract types?)</li><li>the level of abstraction and genericity (do you take advantage of polymorphism, parameterized types?)</li><li>code quality (comments, conciseness)</li><li>your answers to questions during the quick demo</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('0836c5b9') ;
|
||||
//]]>
|
||||
</script></section><section class="yfold"><h2 class="yfold-title" onclick="toggleYfold('577bfcbf')"><span class="arrow" id="arrow-577bfcbf">▸</span>Getting help</h2><div class="yfold-content flex" id="content-577bfcbf" data-yfold-default="hide"><section class="debug flex2 card"><h3 class="debug">Resources</h3><ul class="debug resources"><li>Many resources about OCaml: <a class="debug url" target="_blank" href="https://ocaml.org/">//ocaml.org/</a></li><li><a class="debug" target="_blank" href="https://ocaml.org/learn/books.html">Books </a>to learn OCaml.</li><li>The very <b class="debug">official </b><a class="debug" target="_blank" href="http://caml.inria.fr/pub/docs/manual-ocaml/">OCaml manual</a>. </li><li>A well-written french book about functional programming (Bib'INSA): <br/><b class="debug">Mini Manuel de Programmation Fonctionnelle</b>—<i class="debug">Éric Violard</i>—DUNOD 978-2-10-070385-2</li><li><a class="debug" target="_blank" href="https://ocamlverse.github.io/">OCamlverse </a>: some documentation about OCaml.</li></ul></section><section class="debug flex3 card"><h3 class="debug">OCaml at home</h3><ul class="debug"><li>See <a class="debug" target="_blank" href="https://ocaml.org/docs/install.html">how to install</a>. <br/><small class="debug pcom">The recommended way is OPAM on linux.</small></li><li>Install packages text, utop and ocaml-top.</li><li>On windows, see how to install <a class="debug" target="_blank" href="https://www.typerex.org/ocaml-top.html">ocaml-top</a>. <small class="debug pcom"> (Have you considered switching to a decent, free OS ?)</small></li></ul></section><br/><section class="stupid-flex-separator mml"><h5>A stupid separator, because flex sucks in css.</h5></section><section class="yfold card flex3"><h3 class="yfold-title" onclick="toggleYfold('19360194')"><span class="arrow" id="arrow-19360194">▸</span>Trouble?</h3><div class="yfold-content" id="content-19360194" data-yfold-default="hide"><h4>Packages</h4><ul><li>If you need to use a package, e.g. <code class="inline">text</code> in an interpreter, you must start your program as follows:<br/><code class="block"><span class="directive">#use</span> <span class="string">"topfind"</span> <span class="semi">;;</span> <span class="comment">(* Done once *)</span>
|
||||
<span class="directive">#require</span> <span class="string">"text"</span> <span class="semi">;;</span> <span class="comment">(* For every package you need. *)</span>
|
||||
</code></li></ul><h4>Pitfalls</h4><ul><li><b>Sequence</b>: when writing a sequence, do not put a <code class="block">;
|
||||
</code> on the last statement.<br/><code class="block"><span class="kw">let</span> <span class="letvar">f</span> () =
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Meet"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"John"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Doe"</span> ;
|
||||
<html class="ocaml" lang="en" id="h" xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">g</span> x = x + <span class="number">1</span> <span class="comment">(* Error detected here. *)</span>
|
||||
<head>
|
||||
<title>Functional programming in OCaml</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>
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">h</span> x = x - <span class="number">1</span>
|
||||
</code><ul><li>An error is detected at the end of the definition of g.</li><li>It is difficult to understand why the error appears there (try to find out).</li><li>The real error is the extra <code class="inline">;</code> at the end of <var>f</var><small class="pcom"> (after "Doe")</small>. </li></ul>To avoid this problem, always finish a sequence with unit (and no semicolumn), in order to mark clearly the end of the sequence:<br/><code class="block"><span class="kw">let</span> <span class="letvar">f</span> () =
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Meet"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"John"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Doe"</span> ;
|
||||
()
|
||||
<body>
|
||||
<div class="header" id="header">
|
||||
<h1 id="title">Functional programming in OCaml</h1>
|
||||
</div>
|
||||
<main>
|
||||
<section class="yfold">
|
||||
<h2 class="yfold-title" onclick="toggleYfold('f6c61644')"><span class="arrow" id="arrow-f6c61644">▸</span>Introduction</h2>
|
||||
<div class="yfold-content flex" id="content-f6c61644" data-yfold-default="hide">
|
||||
<section class="debug flex2 card">
|
||||
<h3 class="debug">About the course</h3>
|
||||
<p class="debug">Intended for functional beginners already familiar with some programming language.</p>
|
||||
<h4 class="debug">Goals</h4>
|
||||
<p class="debug">If all goes well, by the end of this course, you shall be able to:</p>
|
||||
<ul class="debug success">
|
||||
<li>Understand <b class="debug">lambda-terms</b> and write <b class="debug">pure functional programs</b>. </li>
|
||||
<li>Design <b class="debug">recursive functions</b> to iterate over recursive <b class="debug">data types</b>. </li>
|
||||
<li>Wonder how you have survived so far without <b class="debug">algebraic data types</b> and <b class="debug">parameterized types</b>. </li>
|
||||
<li>Think in terms of <b class="debug">higher-order functions</b> in order to write reusable code. </li>
|
||||
<li>Astonish yourself by writing <b class="debug">polymorphic functions</b> without even noticing. </li>
|
||||
</ul>
|
||||
<h4 class="debug">Evaluation</h4>
|
||||
<p class="debug">The exam is on october, 12th: a list of exercises, on computer.</p>
|
||||
</section>
|
||||
<section class="debug flex1 card">
|
||||
<h3 class="debug">Setup</h3>
|
||||
<ul class="debug steps">
|
||||
<li>To use OCaml at INSA, copy to your homedir <span class="debug file">/mnt/commetud/GEI/OCaml/.profile</span> and <b class="debug">read it.</b></li>
|
||||
<li>Open a new terminal and launch utop: <code class="debug command">utop</code><br class="debug vskip" />You should get a nice greeting message. Press CTRL+D to quit.</li>
|
||||
<li>Alternatively, you can write small OCaml programs directly on <a class="debug" target="_blank" href="https://try.ocamlpro.com/">Try OCaml</a>. </li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('f6c61644');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h2 class="yfold-title" onclick="toggleYfold('bf745052')"><span class="arrow" id="arrow-bf745052">▸</span>Programming assignments (lessons)</h2>
|
||||
<div class="yfold-content" id="content-bf745052" data-yfold-default="hide">
|
||||
<p>Each lesson must be worked <b>individually</b>, and completed before starting the next one.</p>
|
||||
<aside class="answers">
|
||||
<h4>Answers</h4>
|
||||
<ul>
|
||||
<li>Lesson 1: <a class="caml_c" href="OCaml/all-answers/xkzb/lesson1.ml.html" data-eliom-c-onclick="1E4MGQOS9wC5">lesson1.ml</a></li>
|
||||
<li>Lesson 2: <a class="caml_c" href="OCaml/all-answers/hitj/lesson2.ml.html" data-eliom-c-onclick="Grw/MZP+WPeg">lesson2.ml</a></li>
|
||||
<li>Lesson 3: <a class="caml_c" href="OCaml/all-answers/lcdz/lesson3.ml.html" data-eliom-c-onclick="xypUTosu6RUM">lesson3.ml</a></li>
|
||||
<li>Lesson 4: <a class="caml_c" href="OCaml/all-answers/pmyd/lesson4.ml.html" data-eliom-c-onclick="PCFy+czkv2Rs">lesson4.ml</a></li>
|
||||
<li>Lesson 5: <a class="caml_c" href="OCaml/all-answers/fwiz/lesson5.ml.html" data-eliom-c-onclick="R4j/cMya1IJ+">lesson5.ml</a></li>
|
||||
<li>Lesson 6: <a class="caml_c" href="OCaml/all-answers/dmug/lesson6.ml.html" data-eliom-c-onclick="vZsEvcolLYjP">lesson6.ml</a></li>
|
||||
</ul><small class="pcom">Some solutions might be out of date, or unclear—<br />signal them to Mr. Le Botlan, then.</small>
|
||||
</aside>
|
||||
<ul class="lessons">
|
||||
<li><a class="caml_c" href="OCaml/sujet1.html" data-eliom-c-onclick="a9t25dVDYCcf"><span class="lbutton">Lesson 1</span>The ocaml interpreter, ground types, built-in types.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/sujet2.html" data-eliom-c-onclick="v9VgLpqlyO9u"><span class="lbutton">Lesson 2</span>Functions, curryfication.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/sujet3.html" data-eliom-c-onclick="nVoR9pY+HmLK"><span class="lbutton">Lesson 3</span>Pattern matching, inner let.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/sujet4.html" data-eliom-c-onclick="x/OhOTSgZ4w2"><span class="lbutton">Lesson 4</span>Type structures.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/sujet5.html" data-eliom-c-onclick="B3smUwRNlwiX"><span class="lbutton">Lesson 5</span>Algorithms and more type structures</a></li>
|
||||
<li><a class="caml_c" href="OCaml/sujet6.html" data-eliom-c-onclick="s69LFl2Iqlfj"><span class="lbutton">Lesson 6</span>Compilation, exceptions, side effects.</a></li>
|
||||
</ul><br class="vskip" />
|
||||
<h4>For the curious, some complementary information</h4>
|
||||
<ul>
|
||||
<li><a target="_blank" href="https://reasonml.github.io/">Facebook's REASON</a>, or how to program in OCaml while pretending to write Javascript.</li>
|
||||
<li>Xavier Leroy, proficient developper of the Ocaml compiler, tells <a target="_blank" href="http://gallium.inria.fr/blog/intel-skylake-bug/">how he ran into a bug in some Intel processors</a>. </li>
|
||||
<li>Watch 👁<a target="_blank" href="https://youtu.be/-PX0BV9hGZY">Tail-call recursion, the musical</a>, which explains how call-stacks work.</li>
|
||||
<li>Learn why OCaml's <a target="_blank" href="http://www.ocamlpro.com/2020/03/23/ocaml-new-best-fit-garbage-collector/">Garbage collector</a> is efficient.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('bf745052');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h2 class="yfold-title" onclick="toggleYfold('39af12ce')"><span class="arrow" id="arrow-39af12ce">▸</span>Exam-type exercises</h2>
|
||||
<div class="yfold-content" id="content-39af12ce" data-yfold-default="hide">
|
||||
<aside class="answers">
|
||||
<h4>Answers</h4>
|
||||
<ul>
|
||||
<li>Ex. 1: <a class="caml_c" href="OCaml/all-answers/cnkv/exo1.ml.html" data-eliom-c-onclick="34UoL/1d4mYp">exo1.ml</a></li>
|
||||
<li>Ex. 2: <a class="caml_c" href="OCaml/all-answers/viuq/exo2.ml.html" data-eliom-c-onclick="pRryOPK+/Lta">exo2.ml</a></li>
|
||||
<li>Ex. 3: <a class="caml_c" href="OCaml/all-answers/mfmd/exo3.ml.html" data-eliom-c-onclick="DaTtfOf8fMb5">exo3.ml</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<ul>
|
||||
<li>Exam questions are only intended to test your skills. They are not intended to be smart or enlightening. Thus, do not get surprised if examples are totally unmeaningful.</li>
|
||||
<li>You do not have to write tail-recursive functions, unless explicitly required.</li>
|
||||
</ul>
|
||||
<ul class="lessons">
|
||||
<li><a class="caml_c" href="OCaml/exercises1.html" data-eliom-c-onclick="/knwUQOtRXuQ"><span class="lbutton">Ex. 1</span>Basic types, curried functions, polymorphism, pattern matching</a></li>
|
||||
<li><a class="caml_c" href="OCaml/exercises2.html" data-eliom-c-onclick="fQtG/3W6LzgO"><span class="lbutton">Ex. 2</span>Lists, records, variants.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/exercises3.html" data-eliom-c-onclick="xYhuiXiN7rkq"><span class="lbutton">Ex. 3</span>Recursive structures, exceptions</a></li>
|
||||
<li><a target="_blank" href="https://ocaml.org/learn/tutorials/99problems.html"><span class="lbutton">Ex. 99</span>A list of 99 problems of various difficulty.</a><small class="pcom"> (Some of them are easier than the exam, some are
|
||||
harder.)</small></li>
|
||||
<li><a class="caml_c" href="OCaml/exam-2017.html" data-eliom-c-onclick="gcIDKoTkIR6N"><span class="lbutton">Ex. 2017</span>Exam questions, 2017.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/exam-2019.html" data-eliom-c-onclick="bvximRdiy7/t"><span class="lbutton">Ex. 2019</span>Exam questions, 2019.</a></li>
|
||||
<li><a class="caml_c" href="OCaml/exam-2020.html" data-eliom-c-onclick="wNGyeoaEg24S"><span class="lbutton">Ex. 2020</span>Exam questions, 2020.</a></li>
|
||||
</ul><br class="vskip" />
|
||||
<h4 id="get-prepared">Get prepared for the exam:</h4>
|
||||
<p>The following works only on INSA computers (purposely).</p>
|
||||
<ul>
|
||||
<li>You must have configured your account to use ocaml (see Setup above) </li>
|
||||
<li>In a terminal, launch <code class="command">/mnt/commetud/GEI/run-exam &</code></li>
|
||||
<li>Choose the <b>OCaml Test Exam</b>. The expected password is <kbd>exam</kbd></li>
|
||||
<li>This test exam contains two easy questions.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('39af12ce');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h2 class="yfold-title" onclick="toggleYfold('0836c5b9')"><span class="arrow" id="arrow-0836c5b9">▸</span>Project</h2>
|
||||
<div class="yfold-content" id="content-0836c5b9" data-yfold-default="hide">
|
||||
<p>The project is to be done by pairs of students having the same level.</p>
|
||||
<h4>Requirements</h4>
|
||||
<p>➪ You have completed all the lessons, and know how to write <a target="_blank" href="https://ocaml.org/learn/tutorials/modules.html">OCaml Modules. </a></p>
|
||||
<h4>How it goes</h4>
|
||||
<ul class="steps">
|
||||
<li>The goal is to implement an algorithm computing the max-flow of a flow graph, using the Ford–Fulkerson algorithm, and optionally improve it to take into account other constraints (e.g. minimize cost).<br />See the <a class="caml_c"
|
||||
href="OCaml/project.html" data-eliom-c-onclick="N1JNdzMrXJaN">details of the project</a>. </li>
|
||||
<li>You are free to propose another project, by considering another graph algorithm — check with the teacher.</li>
|
||||
</ul>
|
||||
<h4>Evaluation</h4>
|
||||
<ul>
|
||||
<li>Before <b>december, 12th</b>, you have to send to your teacher (D. Le Botlan or A. Bit-Monnot) a link to your github project <small class="pcom">(or any other similar repository)</small>. </li>
|
||||
<li>Manage to meet your teacher and show him a very quick demo (2 minutes). He will then ask you questions about your project (5-10 minutes).</li>
|
||||
</ul>The final grade takes into account:<ul>
|
||||
<li>your achievements (how much is in your project)</li>
|
||||
<li>your code's modularity (do you use modules, abstract types?)</li>
|
||||
<li>the level of abstraction and genericity (do you take advantage of polymorphism, parameterized types?)</li>
|
||||
<li>code quality (comments, conciseness)</li>
|
||||
<li>your answers to questions during the quick demo</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('0836c5b9');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="yfold">
|
||||
<h2 class="yfold-title" onclick="toggleYfold('577bfcbf')"><span class="arrow" id="arrow-577bfcbf">▸</span>Getting help</h2>
|
||||
<div class="yfold-content flex" id="content-577bfcbf" data-yfold-default="hide">
|
||||
<section class="debug flex2 card">
|
||||
<h3 class="debug">Resources</h3>
|
||||
<ul class="debug resources">
|
||||
<li>Many resources about OCaml: <a class="debug url" target="_blank" href="https://ocaml.org/">//ocaml.org/</a></li>
|
||||
<li><a class="debug" target="_blank" href="https://ocaml.org/learn/books.html">Books </a>to learn OCaml.</li>
|
||||
<li>The very <b class="debug">official </b><a class="debug" target="_blank" href="http://caml.inria.fr/pub/docs/manual-ocaml/">OCaml manual</a>. </li>
|
||||
<li>A well-written french book about functional programming (Bib'INSA): <br /><b class="debug">Mini Manuel de Programmation Fonctionnelle</b>—<i class="debug">Éric Violard</i>—DUNOD 978-2-10-070385-2</li>
|
||||
<li><a class="debug" target="_blank" href="https://ocamlverse.github.io/">OCamlverse </a>: some documentation about OCaml.</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="debug flex3 card">
|
||||
<h3 class="debug">OCaml at home</h3>
|
||||
<ul class="debug">
|
||||
<li>See <a class="debug" target="_blank" href="https://ocaml.org/docs/install.html">how to install</a>. <br /><small class="debug pcom">The recommended way is OPAM on linux.</small></li>
|
||||
<li>Install packages text, utop and ocaml-top.</li>
|
||||
<li>On windows, see how to install <a class="debug" target="_blank" href="https://www.typerex.org/ocaml-top.html">ocaml-top</a>. <small class="debug pcom"> (Have you considered switching to a decent, free OS ?)</small></li>
|
||||
</ul>
|
||||
</section><br />
|
||||
<section class="stupid-flex-separator mml">
|
||||
<h5>A stupid separator, because flex sucks in css.</h5>
|
||||
</section>
|
||||
<section class="yfold card flex3">
|
||||
<h3 class="yfold-title" onclick="toggleYfold('19360194')"><span class="arrow" id="arrow-19360194">▸</span>Trouble?</h3>
|
||||
<div class="yfold-content" id="content-19360194" data-yfold-default="hide">
|
||||
<h4>Packages</h4>
|
||||
<ul>
|
||||
<li>If you need to use a package, e.g. <code class="inline">text</code> in an interpreter, you must start your program as follows:<br /><code class="block"><span class="directive">#use</span> <span
|
||||
class="string">"topfind"</span> <span class="semi">;;</span> <span class="comment">(* Done once *)</span>
|
||||
<span class="directive">#require</span> <span class="string">"text"</span> <span class="semi">;;</span> <span class="comment">(* For every package you need. *)</span>
|
||||
</code></li>
|
||||
</ul>
|
||||
<h4>Pitfalls</h4>
|
||||
<ul>
|
||||
<li><b>Sequence</b>: when writing a sequence, do not put a <code class="block">;
|
||||
</code> on the last statement.<br /><code class="block"><span class="kw">let</span> <span class="letvar">f</span> () =
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Meet"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"John"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Doe"</span> ;
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">g</span> x = x + <span class="number">1</span> <span class="comment">(* No error. *)</span>
|
||||
<span class="kw">let</span> <span class="letvar">g</span> x = x + <span class="number">1</span> <span class="comment">(* Error detected here. *)</span>
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">h</span> x = x - <span class="number">1</span>
|
||||
</code></li><li><b>Nested pattern-matching: </b>be careful when a <code class="block"><span class="kw">match</span>
|
||||
</code> occurs inside another pattern-matching:<br/><code class="block"><span class="comment">(* This (curried) function expects two arguments. *)</span>
|
||||
<span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br/>It does not behave as you think. If you auto-indent the code, you get the real meaning: <br/><code class="block"><span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br/>To fix it, use <code class="kw">begin</code>...<code class="kw">end</code> or parentheses:<br/><code class="block"><span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">begin</span> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
<span class="kw">end</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br/>When a <mark>match is nested in another pattern-matching</mark>, it is good practice to put <code class="kw">begin</code>...<code class="kw">end</code> around it.</li></ul></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('19360194') ;
|
||||
//]]>
|
||||
</script></section><section class="card"><h3>Tutorials</h3><ul><li><a target="_blank" href="http://baturin.org/docs/ocaml-faq/">What I wish I knew when learning OCaml.</a></li><li><a target="_blank" href="https://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html">Local variables (<code class="inline">let .. in ..</code>)</a></li><li><a target="_blank" href="https://medium.com/@bobbypriambodo/getting-your-feet-wet-with-ocaml-ea1045b6efbc">Getting your feet wet with OCaml</a><small class="pcom"> (how to gently install and discover OCaml)</small>. </li><li><a target="_blank" href="https://www.fun-mooc.fr/courses/course-v1:parisdiderot+56002+session04/about">Le MOOC OCaml</a><small class="pcom"> (démarre en septembre 2019)</small></li></ul></section><span class="lbutton mml">❯ contact.lebotlan ❅ insa-toulouse.fr ❮</span></div><script>
|
||||
//<![CDATA[
|
||||
initYfold('577bfcbf') ;
|
||||
//]]>
|
||||
</script></section></main><footer><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:194px;height:42px;" alt="INSA logo" src="Images/logo-insa.jpg"/></a><a target="_blank" href="https://www.laas.fr/"><img title="LAAS" style="width:82px;height:42px;" alt="LAAS logo" src="Images/laas.png"/></a><a target="_blank" href="http://www.univ-toulouse.fr/"><img title="University of Toulouse" style="width:84px;height:42px;" alt="University of Toulouse logo" src="Images/univt.jpg"/></a><small class="pcom"><a class="caml_c" href="yversion.html" data-eliom-c-onclick="HbfuNl/oa5yN">Version information</a></small><a target="_blank" href="http://ocaml.org/"><img title="Powered by OCaml code" style="width:42px;height:42px;" alt="OCaml logo" src="Images/ocaml-small.png"/></a><a target="_blank" href="http://ocsigen.org/"><img title="Website generated by ocsigen & eliom" style="width:38px;height:32px;" alt="Ocsigen logo" src="Images/ocsigen-small.png"/></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>
|
||||
<span class="kw">let</span> <span class="letvar">h</span> x = x - <span class="number">1</span>
|
||||
</code>
|
||||
<ul>
|
||||
<li>An error is detected at the end of the definition of g.</li>
|
||||
<li>It is difficult to understand why the error appears there (try to find out).</li>
|
||||
<li>The real error is the extra <code class="inline">;</code> at the end of <var>f</var><small class="pcom"> (after "Doe")</small>. </li>
|
||||
</ul>To avoid this problem, always finish a sequence with unit (and no semicolumn), in order to mark clearly the end of the sequence:<br /><code class="block"><span class="kw">let</span> <span class="letvar">f</span> () =
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Meet"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"John"</span> ;
|
||||
<span class="uident">Printf</span>.printf <span class="string">"Doe"</span> ;
|
||||
()
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">g</span> x = x + <span class="number">1</span> <span class="comment">(* No error. *)</span>
|
||||
|
||||
<span class="kw">let</span> <span class="letvar">h</span> x = x - <span class="number">1</span>
|
||||
</code>
|
||||
</li>
|
||||
<li><b>Nested pattern-matching: </b>be careful when a <code class="block"><span class="kw">match</span>
|
||||
</code> occurs inside another pattern-matching:<br /><code class="block"><span class="comment">(* This (curried) function expects two arguments. *)</span>
|
||||
<span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br />It does not behave as you think. If you auto-indent the code, you get the real meaning: <br /><code class="block"><span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br />To fix it, use <code class="kw">begin</code>...<code class="kw">end</code> or parentheses:<br /><code class="block"><span class="kw">let</span> <span class="letvar">f</span> x = <span class="kw">function</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">begin</span> <span class="kw">match</span> x <span class="kw">with</span>
|
||||
| <span class="number">0</span> -> <span class="kw">false</span>
|
||||
| <span class="number">1</span> -> <span class="kw">true</span>
|
||||
<span class="kw">end</span>
|
||||
| <span class="number">2</span> -> <span class="kw">true</span>
|
||||
| _ -> <span class="kw">false</span>
|
||||
</code><br />When a <mark>match is nested in another pattern-matching</mark>, it is good practice to put <code class="kw">begin</code>...<code class="kw">end</code> around it.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('19360194');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
<section class="card">
|
||||
<h3>Tutorials</h3>
|
||||
<ul>
|
||||
<li><a target="_blank" href="http://baturin.org/docs/ocaml-faq/">What I wish I knew when learning OCaml.</a></li>
|
||||
<li><a target="_blank" href="https://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html">Local variables (<code class="inline">let .. in ..</code>)</a></li>
|
||||
<li><a target="_blank" href="https://medium.com/@bobbypriambodo/getting-your-feet-wet-with-ocaml-ea1045b6efbc">Getting your feet wet with OCaml</a><small class="pcom"> (how to gently install and discover OCaml)</small>. </li>
|
||||
<li><a target="_blank" href="https://www.fun-mooc.fr/courses/course-v1:parisdiderot+56002+session04/about">Le MOOC OCaml</a><small class="pcom"> (démarre en septembre 2019)</small></li>
|
||||
</ul>
|
||||
</section><span class="lbutton mml">❯ contact.lebotlan ❅ insa-toulouse.fr ❮</span>
|
||||
</div>
|
||||
<script>
|
||||
//<![CDATA[
|
||||
initYfold('577bfcbf');
|
||||
//]]>
|
||||
</script>
|
||||
</section>
|
||||
</main>
|
||||
<footer><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:194px;height:42px;" alt="INSA logo" src="Images/logo-insa.jpg" /></a><a target="_blank" href="https://www.laas.fr/"><img title="LAAS"
|
||||
style="width:82px;height:42px;" alt="LAAS logo" src="Images/laas.png" /></a><a target="_blank" href="http://www.univ-toulouse.fr/"><img title="University of Toulouse" style="width:84px;height:42px;" alt="University of Toulouse logo"
|
||||
src="Images/univt.jpg" /></a><small class="pcom"><a class="caml_c" href="yversion.html" data-eliom-c-onclick="HbfuNl/oa5yN">Version information</a></small><a target="_blank" href="http://ocaml.org/"><img title="Powered by OCaml code"
|
||||
style="width:42px;height:42px;" alt="OCaml logo" src="Images/ocaml-small.png" /></a><a target="_blank" href="http://ocsigen.org/"><img title="Website generated by ocsigen & eliom" style="width:38px;height:32px;" alt="Ocsigen logo"
|
||||
src="Images/ocsigen-small.png" /></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>
|
||||
|
|
40
Y/ystyle.css
40
Y/ystyle.css
|
@ -9,6 +9,7 @@
|
|||
margin: 0px;
|
||||
padding: 0px;
|
||||
box-sizing: border-box;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
/* styles sur html et body pour faire un fond 'polygon' changeant */
|
||||
|
@ -148,8 +149,6 @@ h1, h2, h3 {
|
|||
}
|
||||
|
||||
/* style des éléments a l'intérieur des cartes */
|
||||
.card {}
|
||||
|
||||
.steps {
|
||||
list-style: none;
|
||||
}
|
||||
|
@ -209,7 +208,6 @@ footer .pcom a {
|
|||
/* PAGE DE CODE */
|
||||
code {
|
||||
background: rgba(19, 19, 19, .8);
|
||||
margin-top: 20px;
|
||||
font-family: monospace;
|
||||
color: #ffffcc;
|
||||
display: inline;
|
||||
|
@ -222,7 +220,7 @@ code {
|
|||
.output, samp {
|
||||
display: block;
|
||||
background: rgba(19, 19, 19, .8);
|
||||
margin-top: 20px;
|
||||
margin: 20px 0;
|
||||
font-family: monospace;
|
||||
color: #ccffcc;
|
||||
border-radius: 12px;
|
||||
|
@ -249,6 +247,7 @@ code.block {
|
|||
border-left: 10px solid #944;
|
||||
line-height: 1.55;
|
||||
transition: all .3s;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
code.page {
|
||||
|
@ -391,7 +390,7 @@ code * {
|
|||
}
|
||||
|
||||
.light span.uident {
|
||||
color: rgb(138, 138, 10));
|
||||
color: rgb(138, 138, 10);
|
||||
}
|
||||
|
||||
span.file {
|
||||
|
@ -402,14 +401,6 @@ pre {
|
|||
margin: 20px 0;
|
||||
}
|
||||
|
||||
img.space {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: block;
|
||||
margin-top: 1.5ex;
|
||||
margin-bottom: 1.5ex;
|
||||
}
|
||||
|
||||
span.lbutton {
|
||||
position: relative;
|
||||
margin-right: 6px;
|
||||
|
@ -463,6 +454,29 @@ aside .yfold-title, .card .yfold-title {
|
|||
font-weight: 100;
|
||||
}
|
||||
|
||||
img.space {
|
||||
margin: 25px auto;
|
||||
border-radius: 12px;
|
||||
box-shadow: black 2px 2px 5px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
img.float {
|
||||
margin: 15px auto;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
img[src*="png"] {
|
||||
border: none;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
img:hover {
|
||||
transform: scale(1.05);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
/* MEDIA */
|
||||
@media (min-width: 1400px) {
|
||||
footer {
|
||||
|
|
97
setup.sh
Normal file
97
setup.sh
Normal file
|
@ -0,0 +1,97 @@
|
|||
#!/bin/bash
|
||||
|
||||
lotion_mirror="https://github.com/puneetsl/lotion"
|
||||
required_programs=(git tar 7z wget)
|
||||
|
||||
# Check for required programs
|
||||
for cmd in ${required_programs[@]};
|
||||
do
|
||||
[ ! $(command -v $cmd) ] && echo Command $cmd is required to run this script && exit 1
|
||||
done
|
||||
|
||||
# Select installation destination
|
||||
[ "$EUID" -ne 0 ] && locally="yes" || locally="no"
|
||||
|
||||
installation_folder=$(pwd)
|
||||
case $locally in
|
||||
"yes")
|
||||
echo "Installing for current user. If you want to install globally, run script as sudo"
|
||||
installation_folder=~/.local/share/lotion/
|
||||
executable_folder=~/.local/bin/
|
||||
applications_folder=~/.local/share/applications/
|
||||
;;
|
||||
"no") echo "Installing program for all users. If you want to install program locally, run script without sudo"
|
||||
installation_folder=/usr/share/lotion/
|
||||
executable_folder=/usr/bin/
|
||||
applications_folder=/usr/share/applications/
|
||||
;;
|
||||
esac
|
||||
|
||||
# Select installation type
|
||||
cmd=$1
|
||||
if [[ ! $cmd =~ native|web ]]; then
|
||||
printf "\nSelect an installation type:\n\nweb - Installs the web app at the latest version\nnative - Installs the native windows app at v2.0.9 which has offline support.\n"
|
||||
select cmd in web native
|
||||
do
|
||||
if [[ $cmd =~ native|web ]]; then
|
||||
echo $cmd
|
||||
break
|
||||
else
|
||||
echo "Please input 1 or 2"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Create and copy current lotion folder
|
||||
echo Copying to $installation_folder
|
||||
|
||||
rm -rf $installation_folder
|
||||
mkdir $installation_folder
|
||||
cd $installation_folder
|
||||
cd /tmp
|
||||
|
||||
# Caching
|
||||
if [ -d lotion ];
|
||||
then
|
||||
echo Do you want to use already cached lotion directory ? [yes/no] && read answer
|
||||
case $answer in
|
||||
"N" | "n" | "No" | "no") echo Downloading ... && rm -rf ./lotion && git clone --depth=1 $lotion_mirror ;;
|
||||
"Y" | "y" | "Yes" | "yes") echo Using cached directory ... ;;
|
||||
*) echo Invalid response, using cached directory ;;
|
||||
esac
|
||||
else
|
||||
echo Downloading ...
|
||||
git clone --depth=1 $lotion_mirror
|
||||
fi
|
||||
|
||||
cd ./lotion
|
||||
|
||||
# Create and copy current lotion folder
|
||||
echo Copying to $installation_folder
|
||||
|
||||
rm -rf $installation_folder
|
||||
mkdir $installation_folder
|
||||
cp -rf ./* $installation_folder
|
||||
cd $installation_folder
|
||||
|
||||
# Installation
|
||||
echo "$cmd"
|
||||
if [[ -f install.sh ]]; then
|
||||
./install.sh $cmd
|
||||
else
|
||||
echo Specified installment method \($cmd\) is not avaible
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Linking executables ...
|
||||
# Linking executables for terminal usage
|
||||
ln -s $PWD/Lotion/Lotion ${executable_folder}lotion
|
||||
ln -s $PWD/uninstall.sh ${executable_folder}lotion_uninstall
|
||||
|
||||
echo Copying shortcut ...
|
||||
cp ./Lotion.desktop ${applications_folder}Lotion.desktop
|
||||
|
||||
echo Cleaning ...
|
||||
#./clean.sh
|
||||
|
||||
echo Done !
|
Loading…
Reference in a new issue