Pages

Dec 12, 2013

Life in Death

The truth of life is in death,
is this why our dreams are never met.
We go on with our lives everyday,
while the moment of truth is far away.

Life comes in its many shades,
while the blow of death is always gray.
Hopes are born with beginning of life,
death crushes them with no respite.

But is this really even life ?
filled with pain, sorrow, grief and spite.
When death is the only salvation,
why are we condemned to life's damnation.

Can you really repent your sins,
when you are bound by karma.
Will death be your salvation,
when in life you had no dharma.

Do you live to seek and find,
or to just go on with life's grind.
The seek ends at sundown with death,
when life cannot make further progress.

Death tests our regression into abyss,
filled with guilt and regret of life.
Do we really rise on the other side,
or death takes us for a long ride.

To live one must fight,
there is solace in last rite.
Does our fight go on beyond,
or does it end with the last yawn.

All our lives we move in different boxes,
the move always ends in the same casket.
Is death really the end of a move ?
or, on the other side, our journey begins anew.

When you see my cold dead eyes,
will you still care for the warmth of life ?
When the spirit leaves the humble abode,
does it travel a lonely road ?

We live all our lives divided by life,
while in death we all ultimately unite.
Is death then the only true god ?
when religions are filled with fright and fraud.

And what say we to this humble god,
not today, we are not ready to go abroad.
How long can we keep saying no ?
Does it even matter to all those in the know ?

The cycle of life and death goes on and on,
we come, we go, we shuffle around.
Life in death and death in life,
is there any difference, or, are they alike?

Nov 27, 2013

List Example for Extracting OCaml from Coq

In this post I will show how to extract a simple list append function written in Coq as OCaml code.
First let us create an inductive type in Coq to define our lists as follows.
Inductive mylist : Type :=
| nil : mylist 
| cons : nat -> mylist -> mylist.
Next, we will define an append function over these lists using the "Function" keyword.
Function myappend (l1:mylist) (l2:mylist) {struct l1} : mylist :=
match l1 with
| nil => l2
| cons x xs => cons x (myappend xs l2)
end.
The append function has a special "struct" which tells Coq that the first argument l1 is the recursive parameter to the function. This is essential as without that Coq will not let you define a function. In this particular case the recursive call is always made on a smaller list thus termination can be proven as an instance of structural recursion. However if we write a function where we want to use more general recursion we have to define a "measure" and prove that it decreases with every recursive call. Once the myappend function is defined in Coq it is easy to state and prove properties about append. The following theorem shows that myappend function is associative. 
Theorem myappend_assoc : forall l1 l2 l3 : mylist , myappend (myappend l1 l2) l3 =
(myappend l1 (myappend l2 l3)).
Proof.
intros.
induction l1.
simpl.
trivial.
simpl.
rewrite IHl1.
trivial.
Qed.

Once we have stated the desired properties and proven their correctness we can also generate OCaml (or Haskell) code from Coq using extraction process. The extraction process will recursively remove the proof terms from the code and convert the program to a corresponding OCaml program. Extraction for the myappend function can be using the following statements in Coq.
Extraction Language Ocaml.
Extraction "mylist.ml" myappend.

The generated code in mylist.ml file looks as below.
type nat =
| O
| S of nat
type mylist =
| Nil
| Cons of nat * mylist
(** val myappend : mylist -> mylist -> mylist **)
let rec myappend l1 l2 =
match l1 with
| Nil -> l2
| Cons (x, xs) -> Cons (x, (myappend xs l2))
The OCaml code extracted from Coq includes all the corresponding data types - nat and mylist used in the program. Also the function myappend is extracted without the proof of termination. Other proof constructs like theorems are also dropped from the extracted code. The extracted code can now be used inside a larger OCaml program.


Oct 5, 2013

Using Ocsigen for Web Development with OCaml on Nitrous.IO

As I said in my last post, once you have configured OPAM on nitrous.io, it is quite easy to install additional OCaml libraries and framework. Ocsigen is a web development framework for OCaml. In this post we will see how to configure Ocsigen on nitrous.io to build a simple website with OCaml. To install Ocsigen, just use OPAM
opam install ocsigenserver
After installing Ocsigen we need to install Eliom to enable dynamic websites with Ocsigen. Again run the following command to install it from OPAM.
opam install eliom
If the installations were successful you will now have  a working Ocsigen setup on your machine. In order to test it out let's just create a simple website from the hello world example. Make a new folder in your box inside that copy the following example eliom source file.


 (* ************************************************************************** *)  
 (* Project: Ocsigen Quick Howto : Page                    *)  
 (* Description: Example of a simple page (The famous "Hello World"!)     *)  
 (* Author: db0 (db0company@gmail.com, http://db0.fr/)             *)  
 (* Latest Version is on GitHub: http://goo.gl/sfvvq              *)  
 (* ************************************************************************** *)  
 open Eliom_content  
 open Html5.D  
 open Eliom_parameter  
 (* ************************************************************************** *)  
 (* Application                                *)  
 (* ************************************************************************** *)  
 module Example =  
  Eliom_registration.App  
   (struct  
    let application_name = "example"  
    end)  
 (* ************************************************************************** *)  
 (* Service declaration                            *)  
 (* ************************************************************************** *)  
 let main =  
  Eliom_service.service  
   ~path:[]  
   ~get_params:unit  
   ()  
 (* ************************************************************************** *)  
 (* Service definition                             *)  
 (* ************************************************************************** *)  
 let _ =  
  Example.register  
   ~service:main  
   (fun () () ->  
    Lwt.return  
      (html  
        (head (title (pcdata "Hello World of Ocsigen")) [])  
        (body [h1 [pcdata "Hello World!"];  
            p [pcdata "Welcome to my first Ocsigen website."]])))  

In my box I saved this file as the example/example.eliom. Then I created example/static folder to host the static resources of the website. In order to build this file you can use the magic makefile provided by Ocsigen. Change the static dir to "./static" and  in server files put "example.eliom" , in addition I had to remove the "-noinfer" option from the file as the compiler was giving an error with it. Once you make these changes you can compile your eliom web application example.eliom by typing "make" on the console. It will create a directory structure as follows in the same directory.



The compiled web application is "example.cma". Now we need to launch the Ocsigen server with this web application. For that we take help of the following conf file. 

 <!-- ----------------------------------------------------------------------- -->  
 <!-- Project: Ocsigen Quick Howto                      -->  
 <!-- Description: Configuration file to launch the examples         -->  
 <!-- Author: db0 (db0company@gmail.com, http://db0.fr/)           -->  
 <!-- Latest Version is on GitHub: https://github.com/db0company/Gallery/   -->  
 <!-- ----------------------------------------------------------------------- -->  
 <ocsigen>  
  <server>  
   <port>3000</port>  
   <logdir>./tmp/</logdir>  
   <datadir>./tmp/</datadir>  
   <user></user>  
   <group></group>  
   <commandpipe>./tmp/ocsigen_command</commandpipe>  
   <mimefile>/home/action/.opam/4.01.0/etc/ocsigenserver/mime.types</mimefile>  
   <extension findlib-package="ocsigenserver.ext.ocsipersist-sqlite">  
    <database file="./tmp/ocsidb"/>  
   </extension>  
   <extension findlib-package="ocsigenserver.ext.staticmod"/>  
   <extension findlib-package="eliom.server"/>  
   <charset>utf-8</charset>  
   <debugmode/>  
   <host hostfilter="*">  
    <static dir="./static/" />  
    <eliom module="./example.cma">  
    </eliom>  
   </host>  
  </server>  
 </ocsigen>  
Save the above file as "example.conf" in the same directory and launch the server with the following command.

ocsigenserver -c example.conf 
 This is configure the server to run on the 3000 port as specified in "example.conf" and run the example application. You can test that the application is running using the Preview feature on nitrous.io.



Just use the 3000 port and then the web server should serve the following page in a new window.


This enables nitrous.io to be used as a web development environment for OCaml.  You can now use the Web IDE to develop web applications for OCaml in the same way as you can do for the default boxes supported by nitrous.io. 

Oct 3, 2013

Configuring OPAM for OCaml on Nitrous.IO

In the previous post I showed how to get a working OCaml compiler installed on a nitrous.io box.  We had to get the source code of OCaml from github and build it. It turns out there is a much easier way to get the compiler and all the necessary libraries. We can install the OPAM package manager inside our box and then use OPAM to download additional libraries. In order to configure OPAM on nitrous.io we follow the steps on the quick install page  for the binary installer of OPAM. Run the following commands in the terminal.
wget http://www.ocamlpro.com/pub/opam_installer.sh 
sh ./opam_installer.sh /home/action/.local/bin
The installer will guide you through the process of setting up and installing the OCaml compiler. Once the installation finishes you can use the OCaml system from console. You can also use OPAM to install additional libraries. Details on the usage of OPAM as a package manager are given here. By default it OPAM will install the libraries shown in the screenshot below.