diff --git a/Y/Ada-S1/tps.html b/Y/Ada-S1/tps.html new file mode 100644 index 0000000..e1a63bb --- /dev/null +++ b/Y/Ada-S1/tps.html @@ -0,0 +1,48 @@ + + +TP Ada S1 - premier semestre

Sujets des séances de TP

Configuration

À effectuer obligatoirement une fois en début d'année.

Nous allons configurer une fois pour toutes l'installation emacs/Ada 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).

  • Trouvez le dossier COMMETUD : il devrait y avoir un lien sur votre bureau.
  • Allez dans Commetud, 1ere Année, Ada, puis Setup.
  • Lancer le programme setup-exe en cliquant dessus.
  • 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.

Les sujets

Vous avez cinq séances de TP pour effectuer les missions suivantes :

Acteurs utilisés

Acteurs utilisés au premier semestre :

INSA-Air


Tous les acteurs GAda (vous n'en avez pas besoin au premier semestre)

GAda

Problèmes techniques

Si emacs plante, voici la marche à suivre :

  • Cacher la fenêtre emacs ayant planté (minimiser la fenêtre en cliquant sur le 'moins' en haut à droite).
  • Rouvrir le fichier mission1.adb (par exemple)
  • Lorsque vous tentez de modifier le fichier, emacs se plaint de ne pas pouvoir l'éditer, dans ce cas, appuyer sur la touche 's' (comme steal ou comme c'est moi le chef ).

Facultatif : si vous voulez aussi détruire la fenêtre emacs ayant planté

  • Ouvrir un TERMINAL (à trouver dans le menu Système, ouvrir une console ou un terminal).
  • Dans le terminal, écrire : xkill (puis entrée)
  • Cliquer sur la fenêtre que vous voulez détruire (la fenêtre du emacs ayant planté).

Exercices complémentaires

Tous ces exercices sont faisables sur tech-io. Vous devriez être capables d'effectuer les exercices suivants seuls :Cet ensemble d'exercices correspond exactement au niveau attendu à l'examen :

Compétences et évaluation

Compétences Algorithmiques du semestre 1

Le domaine UF Maths-Algo est évaluée par compétences. Les compétences d'algo sont classées dans trois macro-compétences, de difficulté croissante :

StarBases de programmation

(le minimum vital à acquérir)
  • Traduire une spécification de sous-programme (boîte) en une déclaration de procédure ou de fonction Ada.
  • Distinguer les structures de contrôle while, if, et for.
  • Dans une procédure ou fonction, savoir utiliser les arguments.
  • Écrire une procédure de test qui invoque une fonction, affiche ses arguments et son résultat.
  • Respecter les conventions de présentation (indentation, espacements, commentaires, nommage des variables).

StarStarÉléments d'algorithmique

(l'objet principal du cours)
  • Appliquer toutes les règles de construction d'un programme (typage).
  • Les programmes sont cohérents et compilent sans erreur.
  • Prévoir le résultat d'un programme (sémantique).
  • Manipuler les types articles
  • Essentiel : les algorithmes classiques (min, max, moyenne).

StarStarStarAlgorithmique fine

(pour obtenir le niveau A+)
  • Pour le niveau A+ : algorithmes classiques avec un traitement supplémentaire, par exemple filtrage.

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.

Toutes les compétences n'ont pas le même poids. Par exemple, la distinction des blocs IF, WHILE, FOR 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.

Évaluations

  • Un contrôle Moodle, début octobre. Durée 45 min.
  • Évaluation principale : un contrôle de TP sur ordi, début novembre. Durée 1H30.

Pendant les évaluations, le seul document autorisé est l'aide-mémoire, possiblement annoté.

Bibliographie et conseils sur la méthode de travail

Biblio

  • L'algorithmique (votre passeport informatique pour la programmation). Bruno Warin, Ellipses (ISBN 2729811400).
  • Initiation à l'Informatique (Programmation, Algorithmique, Architectures). Henri-Pierre Charles, Eyrolles (ISBN 2212090498)
  • Apprendre à programmer (Algorithmes et conception objet), Partie I. Christophe Dabancourt, Eyrolles (ISBN 9782212123500)

Conseils

  • 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).
  • Pendant les séances de TP, reportez à la fin de votre aide-mémoire les erreurs de compilation 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.
  • 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.
  • Entre deux séances de TP, relisez les algorithmes et programmes que vous avez effectué à la séance précédente, en comprenant bien chaque étape. Identifiez dans votre aide-mémoire ce que vous avez appris.
  • Rappel : vous pouvez librement contacter vos enseignants de TD, TP ou de cours pour poser des questions.

Ada en dehors des heures de TP

Pour travailler Ada à l'INSA

Des salles informatiques sont en accès libre : la salle du CSN (au centre informatique), et les salles du sous-sol si vous parvenez à y accéder.

Pour travailler Ada depuis chez soi, en se connectant sur un serveur de l'INSA (avec connexion VPN)

  1. Avoir une connexion VPN qui fonctionne : le client VPN de l'INSA
    ou le VPN expliqué par WikEtud.
  2. Puis visiter : //montp.insa-toulouse.fr et choisir une session linux.
  3. En cas de problème technique, envoyez un email à infrastructure-csn à insa-toulouse.fr.

Pour travailler Ada directement sur son propre ordi, chez soi (sans connexion internet)

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.

Aucune connaissance technique n'est nécessaire. Il suffit de suivre les consignes indiquées pour installer une machine virtuelle.

Tech.io (connexion internet, pas de VPN)

Alternative : vous pouvez travailler directement sur tech.io :

Enfin, notez que le club INFO vous aide à installer l'environnement - contactez-les.

diff --git a/Y/OCaml/exam-2020.html b/Y/OCaml/exam-2020.html index 6266286..627d863 100644 --- a/Y/OCaml/exam-2020.html +++ b/Y/OCaml/exam-2020.html @@ -1,4 +1,45 @@ -OCaml - Exam questions, 2020
Note: there exist many possible solutions to each question.
\ No newline at end of file + + + + OCaml - Exam questions, 2020 + + + + + + + +
+ Note: there exist many possible solutions to each question. +
+ + + + diff --git a/Y/OCaml/project.html b/Y/OCaml/project.html index 2d8c164..c7ee774 100644 --- a/Y/OCaml/project.html +++ b/Y/OCaml/project.html @@ -1,61 +1,243 @@ -OCaml - mini project

Setup and compilation

  • To begin with, create a directory for this project.
  • In order to save time, a few modules have already been written.
    Download these files (save link target as...): graph.mli, graph.ml, gfile.mli, gfile.ml, ftest.ml.
    We will explain these files soon.
  • Since you like downloading stuff, you may also save these files: graph1, graph1.svg.
  • The main file is ftest.ml so, we try to compile it, as taught in lesson 6:
    ocamlc -o ftest ftest.ml(try it) -o ftest indicates the name of the executable.
    Error: Unbound module Gfile
  • Look at the beginning of ftest.ml: we open a module Gfile.
    Lesson learnt: The modules used by the program must be compiled before the program.
  • ocamlc -c graph.ml gfile.ml-c means compile only, no executable is built.
    Error: Could not find the .cmi file for interface graph.mli
  • A file named graph.mli exists. It is the interface of module Graph -
    Lesson learnt: foo.mli must be compiled before foo.ml.
  • ocamlc -c graph.mli graph.ml gfile.mli gfile.ml
    something works, at last.
  • See which files have been produced: ls -l (or more professionally, ls -alhv)
    Compilation of C files
    file.c compiled into file.o (by gcc)
    Compilation of OCaml files
    file.ml compiled into file.cmo (by ocamlc)
    file.mli compiled into file.cmi (by ocamlc)
  • ocamlc -o ftest ftest.ml
    Error: Required module `Gfile' is unavailable
  • This error does not come from the compiler but from the linker.
    Lesson learnt: When linking (building an executable), the modules must be explicitly given.
  • ocamlc -o ftest graph.cmo gfile.cmo ftest.ml
    Note: When linking, the modules must be explicitly given in the order of dependencies.
  • You have obtained an executable ftest.
  • ./ftest (You get a usage message.)
  • Whenever you modify a file, you will have to recompile it as well as all the files that depend on it.

A few more things about compilation

  • Recompiling everything is boring. This is why tools such as GNU make (for almost everything) or ant (for Java) exist. Actually, the java compiler already takes care of dependencies.
  • A couple of build tools exist for OCaml too. Let us give a try to ocamlbuild.
  • First, remove all the compilation files: rm -f *.cmi *.cmo ftest(In order to avoid confusion between tools, ocamlbuild refuses to work if it finds compiled files.)
  • Use ocamlbuild ftest.byte to build the bytecode executable, or ocamlbuild ftest.native to build the native executable. (You need only one of them).
    In case you ask, the compiled files can be found in a directory named _build.
  • ./ftest.byte or ./ftest.native(still prints a usage message, though).

Discover the project modules

  • You cannot compile the project using ocaml-top. Use any text editor instead, e.g. emacs (configured as explained at the beginning of OCaml - Lesson 6) or visual studio code, if you know how to launch it.
    You may enjoy A. Bit-Monnot's setup configuration for VSCode : ocaml-maxflow-project on github.
  • The base project contains two modules and a main program:
    • graph.mli and graph.ml which define a module Graph -
    • gfile.mli and gfile.ml which define a module Gfile -
    • ftest.ml, the main program.
  • Look at the interfaces of Graph -(graph.mli) and Gfile -
    All functions are already implemented in graph.ml and gfile.ml
    You must not modify the module Graph -, but you will have to create new modules and to modify Gfile.
  • Try to understand the graph file format (look at the example graph1 and read quickly gfile.ml)
  • To ease the writing of algorithms, write a new module Tools -, with the following signature (the signature must be in file tools.mli) :
    Interface file
    open Graph + -val clone_nodes: 'a graph -> 'b graph -val gmap: 'a graph -> ('a -> 'b) -> 'b graph -val add_arc: int graph -> id -> id -> int -> int graph -
    Implementation file
    (* Yes, we have to repeat open Graph. *) -open Graph + + OCaml - mini project + + + + -(* assert false is of type ∀α.α, so the type-checker is happy. *) -let clone_nodes gr = assert false -let gmap gr f = assert false -... -
    • clone_nodes gr - returns a new graph having the same nodes than gr, but no arc. (code : one line)
      In order to find your errors more quickly, you may add an annotation : let clone_nodes (gr:'a graph) = ... -
    • gmap gr f - maps all arcs of gr by function f. (⩽3 lines)
    • add_arc g id1 id2 n - adds n to the value of the arc between id1 and id2. If the arc does not exist, it is created.
  • In order to test, you may use an online graph editor (Create a graph), and download your graphs.
  • In order to visualize graphs, we will use the famous Graphviz library.
    Write a new function export - in Gfile - which writes a string graph in dot format (the format understood by graphviz). To understand the expected format, you just have to look at this example (click on the picture to get the source file).
    To generate an image from a dot file, you can use:
    dot -Tsvg your-dot-file > some-output-file.svg

To be done

Some technical support

Debugging

In order to activate debugging:
  • You must create a file named _tags in your project directory (this file is read by ocamlbuild).
    Add the following line:
    true: debug
  • In the terminal, set the variable OCAMLRUNPARAM to b (means: backtrace)
    export OCAMLRUNPARAM="b"then, you can launch your program.

Packages

  • If you use special modules, such as Unix (package name: unix) or Graphics (package name: graphics), you need to tell ocamlbuild to use the corresponding package. In the file _tags, add the following line:
    true: package(unix)
    or
    true: package(unix,graphics,...)
  • In order to build, you have to use:ocamlbuild -use-ocamlfind myprog.native
    ocamlfind (findlib) is a tool written by a prolific OCaml developper: Gerd Stolpmann. It is a library manager for OCaml.

How to start writing the Ford-Fulkerson algorithm (alert: SPOILER)

If you are stuck, you may start by writing a function which finds a path in a graph:

-(* A path is a list of nodes. *) -type path = id list + + +
+
+

Setup and compilation

+
+
    +
  • To begin with, create a directory for this project.
  • +
  • In order to save time, a few modules have already been written.
    Download these files (save link target as...): graph.mli, graph.ml, gfile.mli, gfile.ml, ftest.ml.
    We will explain these files soon.
  • +
  • Since you like downloading stuff, you may also save these files: graph1, graph1.svg.
  • +
  • The main file is ftest.ml so, we try to compile it, as taught in lesson 6:
    ocamlc -o ftest ftest.ml(try it) -o ftest + indicates the name of the executable.
    Error: Unbound module Gfile
  • +
  • Look at the beginning of ftest.ml: we open a module Gfile.
    Lesson learnt: The modules used by the program must be compiled before the program.
  • +
  • ocamlc -c graph.ml gfile.ml-c means compile only, no executable is built.
    Error: Could not find the .cmi file for interface graph.mli
  • +
  • A file named graph.mli exists. It is the interface of module Graph +
    Lesson learnt: foo.mli must be compiled before foo.ml.
  • +
  • ocamlc -c graph.mli graph.ml gfile.mli gfile.ml
    something works, at last.
  • +
  • See which files have been produced: ls -l (or more professionally, ls -alhv)
    +
    +
    +
    Compilation of C files
    + + + + + + + +
    file.c compiled into file.o (by gcc)
    +
    +
    +
    Compilation of OCaml files
    + + + + + + + + + + + + + +
    file.ml compiled into file.cmo (by ocamlc)
    file.mli compiled into file.cmi (by ocamlc)
    +
    +
    +
  • +
  • ocamlc -o ftest ftest.ml
    Error: Required module `Gfile' is unavailable
  • +
  • This error does not come from the compiler but from the linker.
    Lesson learnt: When linking (building an executable), the modules must be explicitly given.
  • +
  • ocamlc -o ftest graph.cmo gfile.cmo ftest.ml
    Note: When linking, the modules must be explicitly given in the order of dependencies.
  • +
  • You have obtained an executable ftest.
  • +
  • ./ftest (You get a usage message.)
  • +
  • Whenever you modify a file, you will have to recompile it as well as all the files that depend on it.
  • +
+
+ +
+
+

A few more things about compilation

+
+
    +
  • Recompiling everything is boring. This is why tools such as GNU make (for almost everything) or ant (for Java) exist. Actually, the java compiler already takes care of dependencies.
  • +
  • A couple of build tools exist for OCaml too. Let us give a try to ocamlbuild.
  • +
  • First, remove all the compilation files: rm -f *.cmi *.cmo ftest(In order to avoid confusion between tools, ocamlbuild refuses to work if it finds compiled files.)
  • +
  • Use ocamlbuild ftest.byte to build the bytecode executable, or ocamlbuild ftest.native to build the native executable. (You need only one of them).
    In + case you ask, the compiled files can be found in a directory named _build.
  • +
  • ./ftest.byte or ./ftest.native(still prints a usage message, though).
  • +
+
+ +
+
+

Discover the project modules

+
+
    +
  • You cannot compile the project using ocaml-top. Use any text editor instead, e.g. emacs (configured as explained at the beginning of OCaml - Lesson 6) or visual studio code, if you know how to launch it.
    You may enjoy A. Bit-Monnot's setup configuration for VSCode : ocaml-maxflow-project on github.
  • +
  • The base project contains two modules and a main program:
      +
    • graph.mli and graph.ml which define a module Graph +
    • +
    • gfile.mli and gfile.ml which define a module Gfile +
    • +
    • ftest.ml, the main program.
    • +
    +
  • +
  • Look at the interfaces of Graph + (graph.mli) and Gfile +
    All functions are already implemented in graph.ml and gfile.ml
    You must not modify the module Graph + , but you will have to create new modules and to modify Gfile.
  • +
  • Try to understand the graph file format (look at the example graph1 and read quickly gfile.ml)
  • +
  • To ease the writing of algorithms, write a new module Tools + , with the following signature (the signature must be in file tools.mli) :
    +
    +
    +
    Interface file
    open Graph -(* 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) - *) -find_path: int graph -> id list -> id -> id -> path option + val clone_nodes: 'a graph -> 'b graph + val gmap: 'a graph -> ('a -> 'b) -> 'b graph + val add_arc: int graph -> id -> id -> int -> int graph + +
    +
    +
    Implementation file
    (* Yes, we have to repeat open Graph. *) + open Graph -
\ No newline at end of file + (* assert false is of type ∀α.α, so the type-checker is happy. *) + let clone_nodes gr = assert false + let gmap gr f = assert false + ... +
+
+ + + +
  • In order to test, you may use an online graph editor (Create a graph), and download your graphs.
  • +
  • In order to visualize graphs, we will use the famous Graphviz library.
    Write a new function export + in Gfile + which writes a string graph in dot format (the format understood by graphviz). To understand the expected format, you just have to look at this + example (click on the picture to get the source file).
    To generate an image from a dot file, you can use:
    dot -Tsvg your-dot-file > some-output-file.svg
  • + + + +
    +
    +

    To be done

    +
    + +
    + +
    +
    +

    Some technical support

    +
    +

    Debugging

    In order to activate debugging:
      +
    • You must create a file named _tags in your project directory (this file is read by ocamlbuild).
      Add the following line: +
      true: debug
      +
    • +
    • In the terminal, set the variable OCAMLRUNPARAM to b (means: backtrace)
      export OCAMLRUNPARAM="b"then, you can launch your program.
    • +
    +

    Packages

    +
      +
    • If you use special modules, such as Unix (package name: unix) or Graphics (package name: graphics), you need to tell ocamlbuild to use the corresponding + package. In the file _tags, add the following line: +
      true: package(unix)
      or +
      true: package(unix,graphics,...)
      +
    • +
    • In order to build, you have to use:ocamlbuild -use-ocamlfind myprog.native
      ocamlfind (findlib) is a tool written by a prolific OCaml developper: Gerd Stolpmann. It is a library manager for OCaml.
    • +
    +

    How to start writing the Ford-Fulkerson algorithm (alert: SPOILER)

    +

    If you are stuck, you may start by writing a function which finds a path in a graph:

    + (* A path is a list of nodes. *) + type path = id list + + (* 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) + *) + find_path: int graph -> id list -> id -> id -> path option + + +
    + +
    +
    + + + + diff --git a/Y/ocaml.html b/Y/ocaml.html index df0dc3b..b09d906 100644 --- a/Y/ocaml.html +++ b/Y/ocaml.html @@ -1,72 +1,277 @@ -Functional programming in OCaml

    Introduction

    About the course

    Intended for functional beginners already familiar with some programming language.

    Goals

    If all goes well, by the end of this course, you shall be able to:

    • Understand lambda-terms and write pure functional programs.
    • Design recursive functions to iterate over recursive data types.
    • Wonder how you have survived so far without algebraic data types and parameterized types.
    • Think in terms of higher-order functions in order to write reusable code.
    • Astonish yourself by writing polymorphic functions without even noticing.

    Evaluation

    The exam is on october, 12th: a list of exercises, on computer.

    Setup

    • To use OCaml at INSA, copy to your homedir /mnt/commetud/GEI/OCaml/.profile and read it.
    • Open a new terminal and launch utop: utop
      You should get a nice greeting message. Press CTRL+D to quit.
    • Alternatively, you can write small OCaml programs directly on Try OCaml.

    Programming assignments (lessons)

    Each lesson must be worked individually, and completed before starting the next one.


    For the curious, some complementary information

    Exam-type exercises

    • 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.
    • You do not have to write tail-recursive functions, unless explicitly required.

    Get prepared for the exam:

    The following works only on INSA computers (purposely).

    • You must have configured your account to use ocaml (see Setup above)
    • In a terminal, launch /mnt/commetud/GEI/run-exam &
    • Choose the OCaml Test Exam. The expected password is exam
    • This test exam contains two easy questions.

    Project

    The project is to be done by pairs of students having the same level.

    Requirements

    ➪ You have completed all the lessons, and know how to write OCaml Modules.

    How it goes

    • 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).
      See the details of the project.
    • You are free to propose another project, by considering another graph algorithm — check with the teacher.

    Evaluation

    • Before december, 12th, you have to send to your teacher (D. Le Botlan or A. Bit-Monnot) a link to your github project (or any other similar repository).
    • 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).
    The final grade takes into account:
    • your achievements (how much is in your project)
    • your code's modularity (do you use modules, abstract types?)
    • the level of abstraction and genericity (do you take advantage of polymorphism, parameterized types?)
    • code quality (comments, conciseness)
    • your answers to questions during the quick demo

    Getting help

    Resources

    • Many resources about OCaml: //ocaml.org/
    • Books to learn OCaml.
    • The very official OCaml manual.
    • A well-written french book about functional programming (Bib'INSA):
      Mini Manuel de Programmation FonctionnelleÉric Violard—DUNOD 978-2-10-070385-2
    • OCamlverse : some documentation about OCaml.

    OCaml at home

    • See how to install.
      The recommended way is OPAM on linux.
    • Install packages text, utop and ocaml-top.
    • On windows, see how to install ocaml-top. (Have you considered switching to a decent, free OS ?)

    A stupid separator, because flex sucks in css.

    Trouble?

    Packages

    • If you need to use a package, e.g. text in an interpreter, you must start your program as follows:
      #use "topfind" ;; (* Done once *) -#require "text" ;; (* For every package you need. *) -

    Pitfalls

    • Sequence: when writing a sequence, do not put a ; - on the last statement.
      let f () = - Printf.printf "Meet" ; - Printf.printf "John" ; - Printf.printf "Doe" ; + -let g x = x + 1 (* Error detected here. *) + + Functional programming in OCaml + + + + -let h x = x - 1 -
      • An error is detected at the end of the definition of g.
      • It is difficult to understand why the error appears there (try to find out).
      • The real error is the extra ; at the end of f (after "Doe").
      To avoid this problem, always finish a sequence with unit (and no semicolumn), in order to mark clearly the end of the sequence:
      let f () = - Printf.printf "Meet" ; - Printf.printf "John" ; - Printf.printf "Doe" ; - () + + +
      +
      +

      Introduction

      +
      +
      +

      About the course

      +

      Intended for functional beginners already familiar with some programming language.

      +

      Goals

      +

      If all goes well, by the end of this course, you shall be able to:

      +
        +
      • Understand lambda-terms and write pure functional programs.
      • +
      • Design recursive functions to iterate over recursive data types.
      • +
      • Wonder how you have survived so far without algebraic data types and parameterized types.
      • +
      • Think in terms of higher-order functions in order to write reusable code.
      • +
      • Astonish yourself by writing polymorphic functions without even noticing.
      • +
      +

      Evaluation

      +

      The exam is on october, 12th: a list of exercises, on computer.

      +
      +
      +

      Setup

      +
        +
      • To use OCaml at INSA, copy to your homedir /mnt/commetud/GEI/OCaml/.profile and read it.
      • +
      • Open a new terminal and launch utop: utop
        You should get a nice greeting message. Press CTRL+D to quit.
      • +
      • Alternatively, you can write small OCaml programs directly on Try OCaml.
      • +
      +
      +
      + +
      +
      +

      Programming assignments (lessons)

      +
      +

      Each lesson must be worked individually, and completed before starting the next one.

      + +
      +

      For the curious, some complementary information

      + +
      + +
      +
      +

      Exam-type exercises

      +
      + +
        +
      • 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.
      • +
      • You do not have to write tail-recursive functions, unless explicitly required.
      • +
      +
      +

      Get prepared for the exam:

      +

      The following works only on INSA computers (purposely).

      +
        +
      • You must have configured your account to use ocaml (see Setup above)
      • +
      • In a terminal, launch /mnt/commetud/GEI/run-exam &
      • +
      • Choose the OCaml Test Exam. The expected password is exam
      • +
      • This test exam contains two easy questions.
      • +
      +
      + +
      +
      +

      Project

      +
      +

      The project is to be done by pairs of students having the same level.

      +

      Requirements

      +

      ➪ You have completed all the lessons, and know how to write OCaml Modules.

      +

      How it goes

      +
        +
      • 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).
        See the details of the project.
      • +
      • You are free to propose another project, by considering another graph algorithm — check with the teacher.
      • +
      +

      Evaluation

      +
        +
      • Before december, 12th, you have to send to your teacher (D. Le Botlan or A. Bit-Monnot) a link to your github project (or any other similar repository).
      • +
      • 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).
      • +
      The final grade takes into account:
        +
      • your achievements (how much is in your project)
      • +
      • your code's modularity (do you use modules, abstract types?)
      • +
      • the level of abstraction and genericity (do you take advantage of polymorphism, parameterized types?)
      • +
      • code quality (comments, conciseness)
      • +
      • your answers to questions during the quick demo
      • +
      +
      + +
      +
      +

      Getting help

      +
      +
      +

      Resources

      +
        +
      • Many resources about OCaml: //ocaml.org/
      • +
      • Books to learn OCaml.
      • +
      • The very official OCaml manual.
      • +
      • A well-written french book about functional programming (Bib'INSA):
        Mini Manuel de Programmation FonctionnelleÉric Violard—DUNOD 978-2-10-070385-2
      • +
      • OCamlverse : some documentation about OCaml.
      • +
      +
      +
      +

      OCaml at home

      +
        +
      • See how to install.
        The recommended way is OPAM on linux.
      • +
      • Install packages text, utop and ocaml-top.
      • +
      • On windows, see how to install ocaml-top. (Have you considered switching to a decent, free OS ?)
      • +
      +

      +
      +
      A stupid separator, because flex sucks in css.
      +
      +
      +

      Trouble?

      +
      +

      Packages

      +
        +
      • If you need to use a package, e.g. text in an interpreter, you must start your program as follows:
        #use "topfind" ;; (* Done once *) + #require "text" ;; (* For every package you need. *) +
      • +
      +

      Pitfalls

      +
        +
      • Sequence: when writing a sequence, do not put a ; + on the last statement.
        let f () = + Printf.printf "Meet" ; + Printf.printf "John" ; + Printf.printf "Doe" ; -let g x = x + 1 (* No error. *) + let g x = x + 1 (* Error detected here. *) -let h x = x - 1 -
      • Nested pattern-matching: be careful when a match - occurs inside another pattern-matching:
        (* This (curried) function expects two arguments. *) -let f x = function - | 0 -> false - | 1 -> match x with - | 0 -> false - | 1 -> true - | 2 -> true - | _ -> false -
        It does not behave as you think. If you auto-indent the code, you get the real meaning:
        let f x = function - | 0 -> false - | 1 -> match x with - | 0 -> false - | 1 -> true - | 2 -> true - | _ -> false -
        To fix it, use begin...end or parentheses:
        let f x = function - | 0 -> false - | 1 -> begin match x with - | 0 -> false - | 1 -> true - end - | 2 -> true - | _ -> false -
        When a match is nested in another pattern-matching, it is good practice to put begin...end around it.

      Tutorials

      ❯ contact.lebotlan ❅ insa-toulouse.fr ❮
      \ No newline at end of file + let h x = x - 1 +
      +
        +
      • An error is detected at the end of the definition of g.
      • +
      • It is difficult to understand why the error appears there (try to find out).
      • +
      • The real error is the extra ; at the end of f (after "Doe").
      • +
      To avoid this problem, always finish a sequence with unit (and no semicolumn), in order to mark clearly the end of the sequence:
      let f () = + Printf.printf "Meet" ; + Printf.printf "John" ; + Printf.printf "Doe" ; + () + + let g x = x + 1 (* No error. *) + + let h x = x - 1 + +
    • +
    • Nested pattern-matching: be careful when a match + occurs inside another pattern-matching:
      (* This (curried) function expects two arguments. *) + let f x = function + | 0 -> false + | 1 -> match x with + | 0 -> false + | 1 -> true + | 2 -> true + | _ -> false +
      It does not behave as you think. If you auto-indent the code, you get the real meaning:
      let f x = function + | 0 -> false + | 1 -> match x with + | 0 -> false + | 1 -> true + | 2 -> true + | _ -> false +
      To fix it, use begin...end or parentheses:
      let f x = function + | 0 -> false + | 1 -> begin match x with + | 0 -> false + | 1 -> true + end + | 2 -> true + | _ -> false +
      When a match is nested in another pattern-matching, it is good practice to put begin...end around it.
    • +
    +
    + +
    +
    +

    Tutorials

    + +
    ❯ contact.lebotlan ❅ insa-toulouse.fr ❮ +
    + +
    +
    + + + + diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..4517d87 --- /dev/null +++ b/setup.sh @@ -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 !