Friday, October 31, 2014

Irmin Irmin on the wall, who is the pretiest of them all - Moana

I am currently working on MoanaML.

My recent challenge was to code a backend based on Mirage/Irmin.

Ok, first thing first, what is Moana:

Moana, an information-centric middleware for distributed services and applications. Moana offers a shared graph-based storage abstraction through which applications communicate with each other by appending and observing the shared graph.
Moana supports two basic operations of ADD and MAP; add allows an application to persistently extend the global graph, and map provides a dynamically maintained mapping of the global graph to an application specific, internal sub-graph.
MoanaML is an implementation of the Moana primitives in OCaml.

Now, what is Irmin:

Irmin is a distributed database with built-in snapshot, branch and revert mechanisms. It is designed to use a large variety of backends, although it is optimized for append-only store.
 
Just  to recap, at the moment, MoanaML contains:

Here I wanted to summaries some of my initial progress on developing the Irmin backend for Moana.

To code Irmin-based backed we need to implement two Moana signatures, namely STORE and GRAPH

I am a noobie when it comes to Irmin, I am still trying to figure out all of its functionalities so proceed with caution :)

I recommend reading this blog post to get a better understanding on Irmin, also I found this short paper very insightful. For better code understanding, make sure you familiarise yourself with the lwt library.

So to use Irmin, I chose to use blocks of type String, just because it is provided; to have different types of values you need to implement your own IrminContents signature. This, from my understanding, involves letting Irmin know how to merge your values.

Ultimately, I want to use Irmin to store Moana tuples, not strings, so I will have to implement the Contents signature. For now, I convert Moana tuples into JSON string and store them in Irmin.

Now to the code...


Following Irmin examples, I first implemented t_of_view  and view_to_t functions to convert list of tuples to view and take list of tuples from the view, respectively. I later use these functions to store the views inside Irmin.

The cool thing about Irmin that all  my data is stored in git.

Thanks to this:

module Git =
  IrminGit.FS(struct let root = Some "/tmp/irmin/moana"
                        let bare = true
                           end)
 
(* Values are Strings * *)
module Store = Git.Make(IrminKey.SHA1)(IrminContents.String)(IrminTag.String)

You can also visualise it!




Thursday, October 23, 2014

MoanaML - status report

I have started to work on implementing Moana key functional primitives in OCaml.

The code is available on github here.


My last commit included implementation of the join AM BM  function which binds the tuples available in AM with the intermediate "solution" tuples in the BM. The concepts are taken from the RETE  algorithm. However, unlike RETE this  is still a "static system". By that I mean that join operations are performed on pre-populated AMs.

RETE's left/right activations allow for a more dynamic system. The idea is that each time a new tuple is added to an AM right activation is performed which triggers left activation from the BM, a sequence of these activation will lead to a new result in the newly created final BM.

This is my next step...along with writing more unit tests and fixing existing bugs. If you have any cool ideas on how to take MoanaML further feel free to contribute and Pull Request.
 


Monday, October 6, 2014

Ocaml teaching resources

[Update: The Ocaml teaching resource page is now live]

I am helping the folks behind OCaml.org with setting up a page that will useful resources for educators that want to teach OCaml to masses.

We are looking to include helpful guides on how to setup a development environment, provide links to useful VMs as well as list some tips for complete beginners. There is a lot of material on the web, however it is scattered all over the places and sometimes hard to find. We will try to find the best of the lot and have them referenced in one place.

Watch this space...I really meant this space.

We are also listing all the universities where OCaml is being taught.

Let us know if we missed any.

It is great to see them on the Google maps as well :)

Thursday, October 2, 2014

Learning OCAML: OcaIDE

OCAML has a growing and loyal community behind it, OCAML.org is a great place to get in touch and contribute.
Nevertheless, in my journey I found in difficult to find much material that is tailored for a total noobie.  This is why I decided to document my journey towards functional-language enlightenment, namely by learning and using OCAML language for  developing the MoanaML  project. Your feedback, guidance and contributions are most welcomed.

So here were are, let's start exploring...our glory awaits! :) By the way, I am running Ubuntu 14.04, so most of my tips will be related to it.

I tend to learn most by doing and to do something useful you need the right tools.

Therefore I think the first post about my journey should be on finding and using the right IDE 1. There are not many options around, but there are a few. Your main trade off is on how much time you spend fiddling with them.

I tried a few in all the cases I had to tweak the settings and configuration to get reasonable performance. In the end, I started using OcaIDE, which is a plugin for Eclipse. It is far from perfect, but gives you the initial support a noobie might need to get started.

  • Source editor for modules (ml files), interfaces (mli files), parsers (mly files) and lexers (mll files)
  • Syntax coloring (colors and styles are configurable)
  • Automatic indentation while typing in the editor (configurable in the preferences)
  • A customizable integrated code formatter, and an interface to the camlp4 formatter (through an AST printer)
  • Completion
  • Library browser, both for the standard library and user libraries

    . . . and much more.

Out of all the Eclipse plugins OcaIDE works pretty much out of the box. However you need to make sure you specify your build command in the Project preferences. This is also the right place to specify all the libraries and/or external packages the you are planning to use in your project.

In any case, the OcaIDE project offers Flash-based tutorials on how to set-up and best utilised your developing environment.

You can find step-by-step instructions for it here from guys in UPenn, which include info on how to install OCAML, Eclipse and finally OcaIDE.
A nice summary of how to install OCAML on different enviroment is also presented by the OCAML.org here.

There is plenty of discussion online about a suitable IDE, here are the links to some of it:







1 I am not a big fan of Vim and Emacs, so I wanted to find and IDE that gives me slightly more than just syntax highlight and indentation - just kidding :)  This  is a very gross underestimation of the true power behind Vim and Emacs editors, they are truly powerful tools once you master them. I guess in my case, I preferred to minimize my effort on fiddling with the developing environment and remembering key combinations and rather focus on the OCAML language itself. Nevertheless, as it turned out, choosing an IDE introduced plenty of fiddling with configuration as well. You can find numerous Stack Overflow discussions about it online.