Thu, 22 May 2014 11:00:00 +0000 Paolo Donadeo — LifeLOG/Computer programming 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 Thanks Mr. Ritchie https://www.donadeo.net/post/2011/thanks-mr-ritchie https://www.donadeo.net/post/2011/thanks-mr-ritchie p.donadeo@gmail.com (Paolo Donadeo) Thu, 13 Oct 2011 21:46:52 +0000 2011-10-13T21:51:51.000Z English Digital life Computer programming Linux Article <div><p class="noindent">Today Unix, or some other operating system deeply inspired by Unix, is pervasive: servers, embedded devices (notably Android, but it's only one) and the “revolutionary” Mac OSX is itself an incarnation of the ideas and works of Dennis Ritchie.</p> <p class="noindent"><a title="Google Search for “Dennis Ritchie”" href="https://donadeo.net/u/4x">Dennis Ritchie</a> worked on Unix more than 40 years ago, and my questions is: what will we use in forty years? Probably something Dennis Ritchie was working some months ago.</p> <p class="noindent">Thanks Mr. Ritchie.</p></div> Words of wisdom… https://www.donadeo.net/post/2011/words-of-wisdom https://www.donadeo.net/post/2011/words-of-wisdom p.donadeo@gmail.com (Paolo Donadeo) Tue, 27 Sep 2011 17:00:00 +0000 2011-09-27T17:00:00.000Z English Job Computer programming Random thoughts <div><p class="noindent">…from <a href="https://en.wikipedia.org/wiki/Edsger_W._Dijkstra" title="Edsger W. Dijkstra - Wikipedia, the free encyclopedia">Edsger Dijkstra</a>: “Program testing can be used to show the presence of bugs, but never to show their absence!”</p></div> 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 Bravo! https://www.donadeo.net/post/2010/bravo https://www.donadeo.net/post/2010/bravo p.donadeo@gmail.com (Paolo Donadeo) Wed, 01 Dec 2010 20:55:33 +0000 2010-12-01T20:55:33.000Z English Digital life Computer programming Random thoughts <div><p class="noindent">Playing with the Google Buzz API I accidentally deleted all of my posts.</p> <p class="noindent">Bravo Paolo!</p></div> Smart programmers https://www.donadeo.net/post/2010/smart-programmers https://www.donadeo.net/post/2010/smart-programmers p.donadeo@gmail.com (Paolo Donadeo) Tue, 30 Nov 2010 22:00:00 +0000 2010-11-30T22:00:00.000Z English Digital life Computer programming Java Random thoughts <div><img class="little left" src="https://www.donadeo.net/static/2010/11/no_java.png" alt="Image with a forbidden Java logo" /> <p class="noindent">Do you remember the old article from Paul Graham about the comparison between Python and Java? It's entitled <a href="">“Beating the averages”</a> and despite the fact that it was written in 2003, it's still relevant.</p> <p class="noindent">Why? <a href="https://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/ArrayUtil.java">Try this</a>, and you will be enlightened.</p> <p class="noindent">Thanks to <a href="https://www.google.com/profiles/birdack">Birdack</a> for this link!</p> <p class="noindent"><em>(Local copy <a href="https://www.donadeo.net/static/2010/11/ArrayUtil.java">here</a> for posterity.)</em></p></div> https://www.donadeo.net/post/2010/smart-programmers#commentary https://www.donadeo.net/post/2010/smart-programmers/feed 1 Incubo PHP https://www.donadeo.net/post/2010/incubo-php https://www.donadeo.net/post/2010/incubo-php p.donadeo@gmail.com (Paolo Donadeo) Thu, 25 Nov 2010 20:10:00 +0000 2010-11-25T20:10:00.000Z Italian 4Sigma Computer programming PHP Random thoughts <div><p class="noindent">Sto facendo la manutenzione di un vecchio sito che <a href="https://www.4sigma.it">avevamo scritto</a> in PHP.</p> <p class="noindent">Avevo pessimi ricordi di PHP, ma non mi ricordavo più <em>quanto</em> fosse un incubo programmare in questo, chiamiamolo così, linguaggio.</p> <p class="noindent">Disgustoso!</p></div> https://www.donadeo.net/post/2010/incubo-php#commentary https://www.donadeo.net/post/2010/incubo-php/feed 1