mardi 13 octobre 2015

OCaml sur Windows 10 avec Emacs

Introduction

Cette fois-ci, nous oublions Eclipse et donc Java, et nous construisons donc un environnement de vieil Unixien de base, utilisant donc ce bon Emacs.

Téléchargement

Nous téléchargeons simplement Cygwin, en sélectionnant tous les packages "ocaml" ainsi que emacs-w32.
Nous téléchargeons également Tuareg depuis cette page (tuareg-2.0.7.tar.gz dans notre cas).

Installation

Nous supposons à nouveau que Cygwin s'installe dans \cygwin64, et que l'utilisateur est "gosseyn". Il n'y a pas de configuration particulière pour Cygwin.

Pour installer tuareg, nous déplaçons son archive dans \cygwin64\home\gosseyn, nous lançons un terminal Cygwin, et tapons (en ajustant s'il le faut les numéros de version):

tar xzf tuareg-2.0.7.tar.gz
cd  tuareg-2.0.7
cp tuareg.el ocamldebug.el /usr/share/emacs/24.5/site-lisp
cat > .emacs << EOF
(setq auto-mode-alist (cons '("\\.ml\\w?" . tuareg-mode) auto-mode-alist))
(autoload 'tuareg-mode "tuareg" "Mode majeur pour éditer du code Caml" t)
(autoload 'camldebug "camldebug" "Exécuter le débogueur Caml" t)
EOF
emacs &

Emacs se lance alors. Pour tester le bon fonctionnement de Tuareg, il sufft d'ouvrir (C-x C-f ou menu) un fichier ocaml. Un menu "Tuareg" doit apparaître, et en lançant un ocaml toplevel (C-c C-s ou menu) un shell ocaml doit apparaître.

dimanche 11 octobre 2015

Installing OCaml with Eclipse on Windows 10

Introduction

This explains the main lines related to working efficiently with O'Caml on Win 10 with Eclipse, as I  experimented it today.

Credits

This was found mainly from here, which is a bit more complex, refered an older version of Eclipse (while still being appliable), and above all, taking too much time to view as it is a video tutorial. The OcalIDE site was also helpful.

Packages 

One has to download the following:
  1. a JDK from Oracle. Here I took JDK 8.60 for win64 from here.
  2. Eclipse from here. I took the "Eclipse for Java" Installer, Windows 64 bits. The current version is called "Mars" a.k.a 4.5.
  3. Cygwin from here. I took setup-x86_64.exe.
All installers were downloaded to my Download directory.

Installation

  1. Install the JDK:this step is straightforward, just run the installer and accept the default directories.
  2. Install Eclipse:in my experience, one should install one eclipse per application domain. Indeed, mixing Eclipse plugins raises compatibility issues, and Eclipse versions themselves change often. Hence I create a Program Files/Eclipse directory, under which all eclipse/ installations fit with a dedicated name. Eclipse comes as a simple ZIP file, from which the "eclipse" directory can be copied as Program Files\Eclipse\java-mars. Setup a shortcut from Program Files\Eclipse\java-mars\eclipse.exe to the desktop.
  3. Install OcalIDE: start Eclipse by clicking on the desktop shortcut and open menu Help/Install new Software. In the top "Work with" box, enter "http://www.algo-prog.info/ocaide/" and type "Return".  In the middle box, select "OcalIDE", then "Next" and validate all the way.
  4. Install Cygwin: I install to c:\cygwin64 (not to "Program Files" as Cygwin doesn't like blank spaces in directory names). I took a local package directory as a subdir of "Downloads". The following packages are required. Then, create an icon on Desktop
    •  ocaml, ocaml-base, ocaml-p4 and ocaml-compiler-libs
    •  make "the GNU version"

Setup

  •  Environment variables: from a Win10 file explorer, right-click "This PC" and select "Properties". On the left margin, click "Advanced system settings". Then in the "Advanced" tab, click at the bottom "Environment Variables".  On the lower box "System variables", select line "Path" then "Edit...". As value, add "C:\cygwin64\bin;" to the beginning. Click "OK" all the way. To make sure it went well, open a command prompt and run the "ocaml" command. The familiar OCaml shell should start
  • OCalIDE: start Eclipse by clicking on the desktop shortcut and open menu Window/Preferences. On the left, select "OcalIDE" then "Paths". In the top box, enter C:\cygwin64\bin then click on the "Apply" box right next to it. The default values for all ocaml paths should appear. Also enter C:\cygwin64\bin\make.exe for "make" and "C:\cygwin64\lib\ocaml" for OCaml lib path.Click "Apply" and "OK" on the bottom.

First Project

Select  "File/New/Project..." then "OCaml/OCaml project". Enter a name for the project, validate. Accept switching to the OCaml perspective. Check the low "Ocaml Toplevel" tab: it should provide a running OCaml shell (version 4.01.0 as of this writing).
For more help, look at some useful tutorials here.  The full manual is supposed to be found directly in Eclipse under Help/Help Index but it does not work on my installation, so there is still some digging to fix that (maybe starting from Eclipse CDT instead of Java).