Functional Programming Koans

Already some time that I haven’t posted something on the blog. That’s the famous trade-off between living and speaking about it. I have choosen the former in the previous weeks. Additionnaly I have posted a lot of new pictures on the gallery.

Koan

The following link points to an interesting page about the functional programming paradigm. Concepts such as currying, higher order functions, side effect or lazy evaluation are spoken of in a koans-like form. A great classic.

Functional Programming Koans

Ocaml Blend

ocaml blend

I don’t know if compiler could be sold as everyday products, and I doubt that we would need a new compiler pack everyday — I would not hope so, if the compiler is well designed and thought it shouldn’t be necessary. Anyway nice pic that come from the following website:

ocaml blend

UV Index

uv index image

Something is quite impressive in Australia, the strength of the sunlight. When we are under sun exposure for a couple of minutes, we quickly feel the strong bite of the sun on our skin. This is not surprising when we look at the uv index down here. For example today Sunday as well as tomorrow Monday, the uv index in Sydney under sunlight is 11. That corresponds to a level judged as extreme. Today it was 9 under cloud, what is already rated as very high.

More info on the uv index:
http://www.uv-index.ch/de/uvindex.html

100 Dollars Laptop

100 Dollars Laptop Image

I have just seen today the press conference webcast of the 100 dollars laptop project of the MIT Media Lab. Very promising and well thought. The idea of giving access to technology to children in developing countries is of course very interesting, be it for the interest in the technology itself, for the integration of the computer in the learning process or to give the opportunity of better education, what is definitely a promising factor for a better economical future. The idea of the power supply provided by a crank (manivelle) on the side of the laptop, of wifi enabled devices building an ad-hoc network, enabling to share an internet access as long as one of them is connected to it, or the possibility to use the device as an e-book reader, with integration of the school books, are however not less interesting.

More details about the project on the link below:
100 Dollars Laptop

Benefits of OCaml

I have found an interesting page detailing the benefits of the OCaml language, compared to standard imperative languages (C, C++, Java). I guess that most of the stated points apply generally to functional languages (e.g. SML) and are not specific to OCaml, though I know too little about Haskell to say something about it.

OCaml Benefits

The Fish Market

If you come to Sydney, I’m sure you will see the Opera House, Harbour Bridge and Bondi Beach and if you have time the Taronga Zoo. But have you thought about your
pappillae ?

I’m sure, for you, Australian food is just roasted meat and vegetables, most time burnt as was our chicken Satay last Sunday at a birthday BBQ.
As Australia is a multicultural country, you find whatever you wish : Italian, Greek, Indian, Lebanese, French which is quite expensive of course and above all Asian : Thai, Cantonese, Japanese, Mongolian … for next to nothing. Imagine you can eat quite a big portion of spicy chicken with rice and a tea pot for only AU$ 6.50 (1 AU$ = 0.97 Swiss Francs). So, why bother about cooking!

I discovered yesterday a paradise for the fish gourmets, the Fish Market at the Harbour. Unbelievable, we find tuna, salmon, big or small fish and moreover lobsters, oysters, blue crabs when they are still raw, sea urchins as well as already prepared seafood plates to take away or eat in, sushis bars, fried prawns, that was just great. Laurence, a friend, bought very small fried fish and ate them at the market’s terrace by the ocean. I bought some fresh scallops (coquilles St-Jacques) which I’m looking forward to cooking tonight.

oCaml

oCaml Logo 

An amazing language that I am using on the project I am working on — goanna — is ocaml (pronounce ocamel). It is an implementation of an ML (Meta Language), a functional language based on the theoretical background of the lambda-calculus. The paradigm is different from the one of imperative languages (like java or C) or declarative languages (like XML if we consider it as a declarative one). It has been created originally as a language to implement theorem provers. In the meantime there is a bunch of well known projects that use it, like MLDonkey to cite just one.

That are some of the points I like in that languages.

It is a statically typed languages where all the typing is done at compilation time. A lot of bugs are caught at that moment. There’s no way to produce a segmentation fault or an abort. It saves quite a lot of time in debugging. Once a program can be successfully compiled, there’s a great deal of chance that it will run the way it is supposed to. In all case, no nasty and hard to find bugs about pointers or out of bound arrays. Of course, like in languages such as Java or C#, there is a garbage collector, so no need to do the memory management oneself like in C/C++, hence no memory leaks.

As a functional language, the functions play an important role. The function are said to be first class citizens, they can be passed as parameter to functions, returned by function and so on. For example if I would like to apply some function to every element of a list, we can do it like that (in interactive mode):

#let rec map f list =
   match list with
     [] -> []
     | head::tail -> f head :: (map f tail)

val map : ('a -> 'b) -> 'a list -> 'b list = < fun >  

# let inc x = x+1;; 
val inc : int -> int = < fun >   

# let l = [4;5;9];; 
val l : int list = [4; 5; 9]  

# map inc l;; 
 - : int list = [5; 6; 10] 

The definition of the function map is the following: we define it to be recursive (rec) and to take a function f and a list as parameter. In case that the list is empty (1st match case), it will return an empty list. Otherwise, it will apply the function f to the first element (the head) and do a recursive call of map for the tail (that is also a list, namely the list consisting of all elements of the original one without the first element). The next line is just the type of that function as infered by the system. We see then how the function works with a function inc, which function is obvious, and a list of integer as parameters.

In ML, ocaml in particular, here is how we can store a tree representing real expressions and define a function eval to evaluate recursively such a tree. I find that sooo elegant, as the whole program remains tiny and can be used to store any real expression.

(* define a realexp type *)
(* it can be a float or an expression consisting of a function and 2 subtrees *) 
type realexp =
     Num of float
     | Exp of (float -> float -> float) * realexp * realexp  

(* let's define an eval expression to get a float from a realexp tree *) 
let rec eval exp =
   match exp with
     Num n -> n
     | Exp (f, op0, op1) -> f (eval op0) (eval op1)  

(* define a tree stucture corresponding to some real expression *) 
(* namely: (3.5 * 4.5) + (2.5 / 1.1)   *) 
let exp = Exp ((+.), Exp (( *.), Num 3.5, Num 4.5), Exp ((/.), Num 2.5, Num 1.1))  

(* evaluate it *) 
let result = eval exp  

(* val result : float = 18.0227272727272734 *)

That’s just excellent! emoticon 

The First Week

Several things to do during the first week of our stay. On monday I went to the building of the National ICT Australia, where I am doing an internship, to meet some of my new collegues and to perform some administrative tasks like the opening of a bank account or the buying of pre-paid phone cards.

View on the Bondi Road
View on the Bondi road from the serviced apartement window

On tuesday we began to look for a place to stay. We decided on the one hand to have a look at the advertisements for independent and furnished flat on some internet sites and on the other hand to look for a room to rent in an apartement together with other students. We began with the former. After a few hours on the internet searching for flats or studio in various area of the city, we did phone calls to agents in order to visit some place. It was not so easy to get a visit relatively quickly. Some of the agents took our phone number but few called back. Later that day we decided to go to the UNSW campus (University of New South Wales), beside the building of the National ICT Australia, to have a look at advertisements for room to rent. We took a bunch of phone numbers and began to do some phone calls. We first visited a few rooms, like 2 if I remember correctly. One of them was in a flat not far from the university. There were an australian guy and his asian girlfriend. However the guy who was in charge of renting the room was not there, so we decided to go back at the university – otherwise it is possible that we would have decided on the spot to stay there.

Then we went to visit another room, this time on the other side in respect to the university, at about 12 minutes of walking distance from the campus. It was in a house with a nice garden, a pool, a lady in her mid 50′s and half a dozen of students from the UNSW. We made our mind and decided to stay there. That place was a bit more expensive than the one who interested us, the room was however bigger and we thought that it would be a nicer place for Silvia to stay, as she is not going to do some special occupation during the day, apart from english courses, visitting the city and various cultural activities.

As the question of the place to stay was handled on tuesday evening, we took then the opportunity on wednesday to visit a little bit the city. Sydney is a nice town. Although about 4 million of people live there, everything has its own relaxed rhythm. No stress and easy going.

Opera House
The Sydney Opera House

On thursday I began my internship. As always, the first activity was to install my computer. My main operating system: Debian stable.

The Flight to Sydney

blue sky

Needless to say that the trip from Switzerland to Australia is rather long. 6 to 7 hours from Zurich to Dubai, our first and unique stopover where we spent a short night of a few hours in a hotel near the airport, and then about 14 hours of flight between Dubai and our destination Sydney. Although I cannot normally sleep in a plane, I somehow managed to do it that time, thanks to the relaxation audio programs available on board. I was quite happy about it. Four hours of sleep are already doing a difference. Silvia was however not able to sleep but could watch a few interesting movies from the on-demand movie system. There were really good films, some of them are probably still scheduled in the cinemas in Switzerland (like the Hitchhicker’s Guide to the Galaxy to cite just one among 150 others). The company, Emirates Airlines contributed to a pleasant journey.

Path of the Plane

The arrival in Sydney was on the saturday 27th of August at about 7 am. For us it was 11pm european time but we decided to stay awake on that day and to go to bed only later in the evening to try to catch the right rhythm as soon as possible. That day we went first to our serviced apartment in the area of Bondi to have some rest and let our luggages, then for a walk at the Bondi beach. Not so much people, as it is winter here in Australia, though 2 dozens of surfers in the water and a bunch of people walking along the beach. Nice afternoon tinted with moments of tiredness and a night of sleep beginning rather early in the evening.

Bondi Beach

The next day on sunday was also a bit odd. Sometimes we were quite tired during the day. But already from monday I was alright with the jetlag, though it took a bit longer to Silvia – about one week – to live normally in the day-night rythm.

Association entre appareils mobiles via codes barre 2D

Je profite de l’occasion pour poster le rapport de mon travail de semestre terminé pendant le semestre précédent.

Visual Code

Il s’agit d’un projet portant sur l’association d’appareil mobile via code barre 2D nommés Visual Codes et en particulier la transmission de données entre 2 appareils mobiles ou un appareil mobile et une station fixe via une séquence de ces codes visuels. Les avantages d’un tel système par rapport à une communication entièrement basée sur un protocol radio (bluetooth ou wlan) sont multiple. D’une part la non dissémination d’informations personnelles lors de la première phase d’une communication (privacy) permettant par exemple de collecter des meta-information sur un service existant. D’autre part la possibilité d’inclure dans les données visuelles des informations permettant l’établissement automatique d’une connexion radio traditionnelle, bluetooth ou wlan, par l’inclusion de l’adresse MAC d’un appareil notamment. Enfin la possibilité d’utiliser les données visuelles pour procéder à une authentification unidirectionnelle ou bidirectionnelle lors de laquelle un code visuel (Visual Code) affiché sur un écran ou imprimé sur un sticker fourni un contexte sûr à l’établissement de la connexion.

L’implémentation a été réalisé, pour le module récepteur, sur un téléphone mobile Nokia 6600 en C++ (dialecte Symbian) et pour le module d’envoi sur une PC en java 1.4.X. Les intéressés trouveront plus d’infos dans le rapport ci-joint, en anglais.

CodeSeqReport-PJ.pdf

::first post

Just a few words about me. I live in Lausanne and Zurich, Switzerland. I am studying Computer Science at the ETHZ in Zurich. I am presently in the 8th semester.

I am going to use the English as the main language for that blog, because if I use French, my mother tongue, the people in Zurich are not going to understand it and if I use German, that will be the case for the people in Lausanne.