Thu, 22 May 2014 11:00:00 +0000 Paolo Donadeo — LifeLOG/Objective Caml Paolo Donadeo's personal Internet site and blog https://www.donadeo.net/ p.donadeo@gmail.com (Paolo Donadeo) Installing OPAM 1.1.1 on a CentOS 6.5 https://www.donadeo.net/post/2014/installing-opam-1-1-1-on-a-cenos-6-5 https://www.donadeo.net/post/2014/installing-opam-1-1-1-on-a-cenos-6-5 p.donadeo@gmail.com (Paolo Donadeo) Wed, 21 May 2014 23:00:00 +0000 2014-05-22T11:00:00.000Z English 4Sigma Computer programming Objective Caml Article <div> <p class="noindent">I'm in this situation: I need to compile an OCaml program on a CentOS 6.5 server. This is actually quite problematic, because CentOS 6.5 provide out of the box a very old OCaml 3.11.2, released by INRIA in January 2010, more than four years ago.</p> <p class="noindent">No problem, <a href="https://opam.ocaml.org/" title="OPAM - Home">OPAM</a> come to the rescue! No. The OPAM team doesn't provide a binary executable compatible with the (actually very old) system libraries present in CentOS. </p> <p class="noindent">Ok, step back: OPAM can be compiled from sources (<a href="https://opam.ocaml.org/doc/Advanced_Install.html" title="OPAM - Advanced Install">instructions here</a>) so it's just a matter of minutes. Again: nope. To compile OPAM you need at least OCaml 3.12.1, while in CentOS we have only 3.11.2.</p> <p class="noindent">Step back: first compile and install OCaml from sources. This time I say no, because the whole point of OPAM is to get an up and running OCaml environment in a few minutes, which is <strong>actually true</strong> in most cases.</p> <p class="noindent">I decide to install OCaml using <a href="https://godi.camlcity.org/godi/get_godi.html" title="Get GODI">GODI</a>, the “old” OCaml source distribution, the one everybody used before OPAM was born. So the fastest steps to have an OPAM and OCaml environment on a CentOS server are:</p> <ul> <li>download and install GODI;</li> <li>clone the <a href="https://github.com/ocaml/opam" title="GITHUB - ocaml/opam">OPAM repository</a>, compile and install it; it will find a “system” compiler provided by GODI;</li> <li><code>$ opam switch 4.01.0</code> will recompile a new environment;</li> <li><code>$ opam switch remove system</code> to delete the “system” environment;</li> <li><code>$ rm -Rf ~/godi</code>.</li> </ul> <p class="noindent">No root access is required in this process, I usually install OPAM in <code>~/opam</code>, and GODI in <code>~/godi</code>.</p> <p class="noindent">There is an irony in all this story: GODI has been <strong>the</strong> OCaml source distribution for years, and the coming of OPAM, which is actually newer and has some important features missing in GODI, has produced many frictions in the OCaml community, that in the end caused the <a href="https://blog.camlcity.org/blog/godi_shutdown.html" title="GODI is shutting down">shut down of GODI</a>.</p> <p class="noindent">The moral part here is: embrace the new things, but don't be too impatient in throwing out the window the precious work that, in the end, still works.</p> <p class="noindent">In any case, I want to thank both Gerd Stolpmann (author of GODI) and the OPAM team: they gave to the OCaml community a mature, industrial grade, set of tools to use OCaml.</p> </div> https://www.donadeo.net/post/2014/installing-opam-1-1-1-on-a-cenos-6-5#commentary https://www.donadeo.net/post/2014/installing-opam-1-1-1-on-a-cenos-6-5/feed 5 First release of OCaml binding of Lua library https://www.donadeo.net/post/2012/first-release-of-ocaml-lua https://www.donadeo.net/post/2012/first-release-of-ocaml-lua p.donadeo@gmail.com (Paolo Donadeo) Sat, 01 Sep 2012 14:06:00 +0000 2012-09-01T14:06:00.000Z English Spare time Computer programming Objective Caml Lua News <div> <p class="noindent">I'm happy to announce the first release of ocaml-lua, the OCaml binding of the Lua library. With ocaml-lua you can embed a Lua interpreter in an OCaml program in a few lines of code, and use Lua for configuration or customization purposes.</p> <p class="noindent">Here are some references:</p> <ul> <li>The homepage of the project is hosted on <a href="https://ocaml-lua.forge.ocamlcore.org/">OCaml Forge</a>;</li> <li>The complete library reference (ocamldoc generated) is <a href=" https://ocaml-lua.forge.ocamlcore.org/api-lua/">here</a>;</li> <li>Source tarballs are on the download page on <a href="https://forge.ocamlcore.org/frs/?group_id=167">OCaml Forge</a>;</li> <li>The official GIT repository is <a href="https://forge.ocamlcore.org/scm/browser.php?group_id=167">here</a>;</li> <li>Bug reports and feature requests are on my page on <a href="https://github.com/pdonadeo/ocaml-lua/issues">GitHub</a>.</li> </ul> <p class="noindent">I hope it could be useful.</p> </div> Debugging memory in OCaml: any advice? https://www.donadeo.net/post/2012/debugging-memory-in-ocaml-any-advice https://www.donadeo.net/post/2012/debugging-memory-in-ocaml-any-advice p.donadeo@gmail.com (Paolo Donadeo) Mon, 27 Feb 2012 23:37:00 +0000 2012-02-27T23:37:00.000Z English 4Sigma Computer programming Objective Caml Article <div> <a title="Memory consumption chart" class="zoom-box-image" href="https://www.donadeo.net/static/2012/02/server_rss.png"><img class="little left" src="https://www.donadeo.net/static/2012/02/server_rss_small.png" alt="Memory consumption chart" /></a> <p class="noindent">A server I just deployed (written in OCaml, of course) seems to eat RAM at breakfast. This is the chart of the RSS field of "ps" in the past 24h (click to enlarge). The program starts with almost 6 Mb and is now reaching 40 Mb, in a linear trend that has nothing good to say.</p> <p class="noindent">Any advice on how to debug the memory consumption?</p> </div> https://www.donadeo.net/post/2012/debugging-memory-in-ocaml-any-advice#commentary https://www.donadeo.net/post/2012/debugging-memory-in-ocaml-any-advice/feed 1 Installing OCaml Batteries https://www.donadeo.net/post/2010/installing-batteries https://www.donadeo.net/post/2010/installing-batteries p.donadeo@gmail.com (Paolo Donadeo) Mon, 13 Dec 2010 22:55:00 +0000 2010-12-13T22:55:00.000Z English Digital life Computer programming Objective Caml Article <div> <p class="noindent">In this post I want to help OCaml newcomers to install Batteries. The task is trivial under Linux, while it's a bit tricky under Windows, because OCaml still lacks a self-contained Windows installer.</p> <p>My assumption is that the reader is a coder, so I will not explain <em>everything</em>… Let's start with the easy part: Linux.</p> <h4>Linux</h4> <p class="noindent">The installation of OCaml + Batteries under a Debian/Ubuntu system couldn't be easier, thanks the the hard work of the <a href="https://wiki.debian.org/Teams/OCamlTaskForce">Debian OCaml Task Force</a>. So open a terminal and type:</p> <pre class="brush: bash"> $ sudo aptitude install ocaml-batteries-included </pre> <p>That's all for Debian/Ubuntu. I don't know how Fedora works, but I think it's easy to install Batteries using YUM, something like:</p> <pre class="brush: bash"> $ yum install ocaml-batteries-included </pre> <p>If a RPM package for Batteries wasn't available, you could still install OCaml, Camomile (the Unicode library), and compile Batteries from sources, as described below for the Windows OS.</p> <h4>Windows</h4> <p class="noindent">As said, this OS still lacks a self contained installer which is in progress, at least for installing OCaml. Since <a href="https://caml.inria.fr/ocaml/release.en.html#id2268363">many OCaml versions</a> are available for Windows, with different <a href="https://caml.inria.fr/ocaml/portability.en.html#windows">pros and cons</a>, I had to decide which one to use, and I decided to follow the simplest path to reach the goal of installing all the stuff we need. The Cygwin port is by far the simplest way.</p> <ol> <li>Download <a href="https://www.cygwin.com/setup.exe">Cygwin setup</a> and double click the executable. In Windows Vista/7 (I made my test on a Windows 7 64bit box) you will be required to allow the program to be run a couple of times, as usual ;-) …</li> <li>when the list of available packages appears, select: each and every package containing "caml" (see the screenshot below), and also <kbd>make</kbd>, <kbd>m4</kbd>, <kbd>libncurses-devel</kbd>, <kbd>git</kbd>, <kbd>wget</kbd> and <kbd>rlwrap</kbd>; <br /> <a title="Necessary Cygwin packages" class="zoom-box-image" href="https://www.donadeo.net/static/2010/12/install_cygwin.png"><img class="little left" src="https://www.donadeo.net/static/2010/12/install_cygwin_small.png" alt="Necessary Cygwin packages" /></a> <br style="clear:both;" /> </li> <li>open the Cygwin shell;</li> <li>download the Findlib library, version 1.2.6: <pre class="brush: bash"> $ wget https://download.camlcity.org/download/findlib-1.2.6.tar.gz </pre> </li> <li>unpack, compile and install Findlib: <pre class="brush: bash"> $ tar -xpzf findlib-1.2.6.tar.gz $ cd findlib-1.2.6/ $ ./configure $ make $ make install </pre> </li> <li>download, unpack, compile and install Camomile 0.8.1: <pre class="brush: bash"> $ wget https://prdownloads.sourceforge.net/camomile/camomile-0.8.1.tar.bz2 $ tar -xpjf camomile-0.8.1.tar.bz2 $ cd camomile-0.8.1/ $ ./configure $ make $ make install </pre> </li> <li>the last step is to download compile and install Batteries itself. I wasn't able to compile the latest stable release (1.2.2), for an obscure preprocessor error, but using the latest GIT branch everything went smoothly. So here are the steps: <pre class="brush: bash"> $ git clone git://github.com/ocaml-batteries-team/batteries-included.git $ cd batteries-included/ $ make camomile82 $ make all doc $ make install install-doc </pre> </li> </ol> <h4>Testing the installation</h4> <p class="noindent">Before starting to play with the library and the <em>toplevel</em> (the OCaml <a href="https://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a> is called toplevel) let's put into action a couple of helpers.</p> <ol> <li>The OCaml toplevel doesn't support readline. To get this feature back we add an alias to <kbd>.bashrc</kbd>. This works in both Linux and Windows: <pre class="brush: bash"> alias ocaml='rlwrap -H /home/paolo/.ocaml_history -D 2 -i -s 10000 ocaml' </pre> restart the terminal or load another bash; </li> <li>we need to load Batteries in the toplevel. This is not strictly necessary, but it helps a lot and the Batteries ASCII logo is wonderful <kbd>:-)</kbd>. All we need is to create a file named <kbd>.ocamlinit</kbd> in the home directory. Open your favorite editor and put this <em>phrases</em> in <kbd>~/.ocamlinit</kbd>: <pre class="brush: ocaml"> let interactive = !Sys.interactive;; Sys.interactive := false;; (*Pretend to be in non-interactive mode*) #use "topfind";; Sys.interactive := interactive;; (*Return to regular interactive mode*) Toploop.use_silently Format.err_formatter (Filename.concat (Findlib.package_directory "batteries") "battop.ml");; </pre> </li> </ol> <p>If everything went well you can now type <kbd>ocaml</kbd> and something like this should appear:</p> <pre style="background-color: #fffdbf; font-weight: bold;"> $ ocaml Objective Caml version 3.11.2 _________________________ [| + | | Batteries - | |_____|_|_________________| _________________________ | - Type '#help;;' | | + |] |___________________|_|___| Loading syntax extensions... Camlp4 Parsing version 3.11.2 </pre> <h4>Conclusions</h4> <p class="noindent">This (rather boring) post has been devoted to the installation details of Batteries under Windows, where it presents some difficulties for newbies. Next time we will start on exploring the library with simple examples to exploit its strength.</p> </div> https://www.donadeo.net/post/2010/installing-batteries#commentary https://www.donadeo.net/post/2010/installing-batteries/feed 5 Pearls of OCaml Batteries (1) https://www.donadeo.net/post/2010/batteries-1 https://www.donadeo.net/post/2010/batteries-1 p.donadeo@gmail.com (Paolo Donadeo) Sun, 05 Dec 2010 15:15:00 +0000 2010-12-05T15:15:00.000Z English Digital life Computer programming Objective Caml Article <div> <img class="little left" src="https://www.donadeo.net/static/2010/11/batteries_logo.png" alt="OCaml Batteries logo" /> <p class="noindent"><a href="https://caml.inria.fr/ocaml/index.en.html">OCaml</a> is known to be a powerful functional programming language, but one of its presumed weakness is a relatively poor standard library.</p> <p class="noindent">By accident, I'm one of the few people on the planet considering this very clean and virtually bug free library a feature and not a bug, but this is only an opinion.</p> <p><a href="https://caml.inria.fr/pub/docs/manual-ocaml/manual034.html">The standard library</a> contains everything you need to build applications and other libraries, but it's <em>essential</em>, forget something like the Python standard library and things like “sending an email in one line of code”. Instead, think of the C standard library (plus some important data structures missing in the libc).</p> <p>More than two years ago the OCaml community decided to start the development of a library containing all the conveniences that are missing in the standard library. The project is <a href="https://batteries.forge.ocamlcore.org/">OCaml Batteries Included</a> and I'd like to introduce the reader with a series of posts, aimed to cast a light on various aspects of the library, without pretending to be an exhaustive tutorial.</p> <p>The posts will be targeted at novice OCaml programmers because I think that an experienced OCaml hacker already uses "Batteries" or, in any case, he understand the library API and doesn't need help from this blog.</p> <p>Before starting with the (boring) installation details, I want to give you a taste of Batteries, to show how a simple task could be written in a more natural way using Batteries modules, in comparison with a <em>vanilla</em> implementation. Let's take this simple task: we want to read a file by lines and print on the terminal only those lines containing a particular substring.</p> <p>A simple and actually working solution is proposed by the <a href="https://pleac.sourceforge.net/pleac_ocaml/">PLEAC-Objective CAML</a> project, it's the very first example of the <a href="https://pleac.sourceforge.net/pleac_ocaml/fileaccess.html">file access</a> section. Here is the proposed code:</p> <pre class="brush: ocaml;"> let () = let in_channel = open_in "/usr/local/widgets/data" in try while true do let line = input_line in_channel in try ignore (Str.search_forward (Str.regexp_string "blue") line 0); print_endline line with Not_found -> () done with End_of_file -> close_in in_channel </pre> <p class="noindent">Now let's rephrase using Batteries:</p> <pre class="brush: ocaml;"> Enum.iter (fun l -> if BatString.exists l "blue" then print_endline l) (open_in "/usr/local/widgets/data" |> BatIO.lines_of) </pre> <p class="noindent">The result is the same, but the code is much cleaner and far more idiomatic for a functional language.</p> <p>Next time we will see how to install OCaml and Batteries, under Linux of course, but hopefully even under Windows.</p></div> https://www.donadeo.net/post/2010/batteries-1#commentary https://www.donadeo.net/post/2010/batteries-1/feed 6 OCaml per programmatori Python https://www.donadeo.net/post/2010/ocaml-per-programmatori-python https://www.donadeo.net/post/2010/ocaml-per-programmatori-python p.donadeo@gmail.com (Paolo Donadeo) Sun, 22 Aug 2010 22:08:00 +0000 2010-08-22T22:08:00.000Z Italian Personal consultancy Computer programming Objective Caml Python Article <div><p class="noindent">Sorry for English speaking people, but this post makes sense only for Italians, so it's in Italian :-)</p> <p>Qualche mese fa, precisamente a fine Febbraio, mi è stato chiesto di presentare in un breve workshop il linguaggio <a href="https://caml.inria.fr/ocaml/index.en.html">Objective Caml</a> che, manco a dirlo, è il mio linguaggio di programmazione preferito. Mi ero riproposto di scrivere qualcosa in merito, ma una serie di problemi me lo ha impedito, così colmo con qualche mese di ritardo la lacuna.</p> <p>L'invito mi è arrivato da <a href="https://www.develer.com/website/en">Develer</a>, un'azienda con sede <a href="https://www.develer.com/website/en/location/">vicino Firenze</a> molto attenta alla formazione ed alle novità nel mondo delle tecnologie informatiche. In questo caso la novità non sta tanto nel linguaggio OCaml, che ha ormai 14 anni, quanto nel volersi avvicinare alla programmazione funzionale con uno sguardo pragmatico.</p> <p>Develer è poi l'azienda che contribuisce in maniera sostanziale alla realizzazione del <a href="https://www.pycon.it/">PyCon Italia</a>, una splendida manifestazione che è un unicum nel panorama culturale italiano, e non solo per i programmatori appassionati di Python, ma per tutti gli sviluppatori e smanettoni sufficientemente <em>smart</em> da non ignorare Python.</p> <p>Il background culturale legato a Python e l'assoluto digiuno di programmazione funzionale hanno portato ad un workshop in cui ho cercato di mostrare alcuni dei concetti della <a href="https://en.wikipedia.org/wiki/Functional_programming">FP</a>, utilizzando OCaml, e spiegandone nel contempo la sintassi in estrema sintesi, mostrando qualche parallelo con Python.</p> <p>Non so se il risultato sia stato positivo per Develer, perché da un lato non sono un vero esperto OCaml, e dall'altro ho dovuto (voluto?) concentrare in poco tempo una serie di concetti non banali, per cui forse non è stato facile per i presenti seguire il discorso. Comunque sia, nessuno mi ha tirato pomodori :-)</p> <p>Per il workshop ho ovviamente preparato una piccola presentazione che potete <a href="https://www.donadeo.net/static/2010/08/ocaml_per_prog_python.pdf">scaricare in formato PDF</a>, sperando possa essere utile a qualcuno, non fosse altro per l'elenco di link a risorse relative ad OCaml. La presentazione è distribuita con licenza <a href="https://creativecommons.org/licenses/by-sa/2.5/it/deed">Creative Commons (Attribuzione, condividi allo stesso modo)</a>, il che vuol dire che se siete così matti da copiarne dei pezzi, almeno ricordatevi di citarmi tra gli autori.</p></div> https://www.donadeo.net/post/2010/ocaml-per-programmatori-python#commentary https://www.donadeo.net/post/2010/ocaml-per-programmatori-python/feed 3 Source repository of this blog https://www.donadeo.net/post/2010/blog-source https://www.donadeo.net/post/2010/blog-source p.donadeo@gmail.com (Paolo Donadeo) Sun, 08 Aug 2010 16:55:00 +0000 2010-08-08T16:55:00.000Z English Digital life Spare time Computer programming Objective Caml News <div><p class="noindent"> Following my previous post, some people <a href="https://www.donadeo.net/post/2010/my-new-blog-in-objective-caml#commentary">asked me</a> to show the source code of this blog, so here it is:<br /> <a href="https://github.com/pdonadeo/personal_blog">https://github.com/pdonadeo/personal_blog</a>.</p> <p>A general warning: the project wasn't thought to be published and so the code is a pile of scripts kept together in some way. Many parameters are present in the SQLite DB, but if you want to use the blog, expect to find my name, surname or email in the HTML templates, or even in some .ml files.</p> <p>Moreover, the source code is not homogeneous and the style changes from module to module, because I changed my way (and skill) of programming in OCaml in time.</p> <p>In any case, I hope you will find it interesting.</p></div> My new blog… in Objective Caml https://www.donadeo.net/post/2010/my-new-blog-in-objective-caml https://www.donadeo.net/post/2010/my-new-blog-in-objective-caml p.donadeo@gmail.com (Paolo Donadeo) Tue, 03 Aug 2010 08:26:00 +0000 2010-08-03T08:26:00.000Z English Digital life Computer programming Objective Caml Article <div><p class="noindent">More than a year ago I decided to dismiss my Wordpress blog, and to write a new one from scratch in OCaml. Unfortunately my spare time for programming projects is getting less and less, so this simple work took a lot of time to reach an usable state.</p> <p>I put online a preliminary release a month ago and immediately several bugs and little problems have arose, so I had to pass through the usual karma of recurring corrections. Now it seems stable.</p> <h4>Software design (strong words, actually!)</h4> <p class="noindent">To write this blog I decided to use <a href="https://projects.camlcity.org/projects/ocamlnet.html">Ocamlnet</a> to produce a FastCGI server, providing dynamic contents through Apache, leaving the HTTP server alone to serve static resources, like Javascript, CSS and images.</p> <p>Ocamlnet is an excellent network framework, but it offers a low level interface, if compared with <a href="https://ocsigen.org/">Ocsigen</a>, which is web specific. Ocsigen (<a href="https://ocsigen.org/eliom/manual/1.3.0/">Eliom</a>, actually) is a complete, modern and mature web framework, and I was afraid I couldn't use it, but AFAIK it lacks the possibility to create a FastCGI executable. I need this kind of setup because the blog runs on a production server of mine, where Apache is already installed and many virtual hosts are configured to run several sites and web apps, written in Django (Python) or even PHP. </p> <p>To write the blog <del>I stole many ideas</del> I was inspired by many ideas taken here and there. It's fair to list them, and to thank the authors:</p> <ul> <li>from Eliom I took the idea of a way to create the parameters of the web page in a type safe way, using <a href="https://ocsigen.org/docu/1.3.0/Eliom_parameters.html">some combinators</a> that describe the expected type of the parameter and rebuild it from the CGI string from the browser. The implementation present in Eliom is of course outstanding, while my piece of code just solves a small subset of the problem of parameters reconstruction;</li> <li>the blog of <a href="https://eigenclass.org/R2/">Mauricio Fernández</a> is written with Ocsigen (<a href="https://github.com/mfp/ocsiblog">source here</a>) and contains a simple <a href="https://eigenclass.org/R2/writings/fast-extensible-simplified-markdown-in-ocaml">markdown-like language processor</a> used to format comments. I wrote something like that, but I'm learning to write parsers combinators so my implementation only processes a subset of the language recognized by Mauricio's parser;</li> <li><a href="https://ambassadortothecomputers.blogspot.com/">Jake Donham</a> wrote lwt-equeue as part of the <a href="https://github.com/jaked/orpc">orpc</a> project. It's a module providing the same interface of <a href="https://ocsigen.org/lwt/">Lwt</a>, but runs on <a href="https://projects.camlcity.org/projects/dl/ocamlnet-2.2.9/doc/html-main/Equeue.html">equeue</a>, the low level event loop engine of Ocamlnet, and I used it to write a simple SMTP client in a monadic way without having to drop Ocamlnet and FastCGI;</li> <li><a href="https://batteries.forge.ocamlcore.org/">Batteries</a> is of course used almost everywhere;</li> <li>as a template engine to render HTML I used <a href="https://forge.ocamlcore.org/projects/camltemplate/">CamlTemplate</a> by Benjamin Geer (maintained by Dmitry Grebeniuk).</li> </ul> <p>The resulting software is far from being well structured and designed, but I wrote yet another blog exactly to have the opportunity to test many libraries and programming paradigms in OCaml and, with respect to this goal, the result is a success :-)</p> <h4>Blog features</h4> <p class="noindent">While the code is a mess, the blog itself has many useful features: a very simple administration to edit posts, RSS feeds, comments, <a href="https://akismet.com/">antispam</a>, and a completely useless URL shortening service available at <a href="https://www.donadeo.net/u">https://www.donadeo.net/u</a>.</p> <h4>Performance</h4> <p class="noindent">What about the performance of the whole object? I don't know how to realistically test the blog, because using the classical <code>ab</code> is rather pointless, since it is generally used with static resources that, in my case, are served by Apache. If someone has some good ideas about 1) how to make a stress test and 2) have some good reference in term of expected hit per second, please don't hesitate and contact me, of course to blame me about how the blog is slow.</p> <h4>Conclusions</h4> <p class="noindent">The blog is up and running and I don't see any particular bug. In the next months I'll probably add some features, like the possibility to follow comments via email, or a decent XML site map.</p></div> https://www.donadeo.net/post/2010/my-new-blog-in-objective-caml#commentary https://www.donadeo.net/post/2010/my-new-blog-in-objective-caml/feed 6