mod_ocaml 0.01

mod_ocaml is an Apache module for the use of OCAML as a Web scripting language.
Generally, mod_ocaml is a flexible module for use with the famous Apache Web Server. Probably you know how to benefit of other modules with unbelievable capabilities, like PHP (mod_php4) or Perl (mod_perl).

One of the advantages of the Apache Server is the possibility to extend its features by adding modules to your configuration. At this point, mod_ocaml comes up.

mod_ocaml is designed to work with the 1.3 family of Apache's all over the world.

OCAML is derived from the CAML language. We include the description from its home at INRIA here:

Caml is a programming language, easy to learn, easy to use, and yet amazingly powerful.

It is developed and distributed by INRIA (the main French research institute for computer science), since 1984. It is freely available for Unix, PC or Macintosh.

Objective Caml (OCAML) is a general purpose programming language that combines
functional, imperative, and object-oriented programming. The language is statically typed; its type system ensures the correct evaluation of programs.

Types are automatically inferred. The language offers powerful constructions such as user-definable data-types, the ability to define functions by pattern-matching, and an exception mechanism. Programming in the large is facilitated by a full-fledge class-based object-oriented layer and an expressive module system.

Installation

Find your installed apxs, usually in /usr/bin, or /usr/local/apache/bin.

Call apxs -c mod_ocaml.c to compile the module

Copy the created file mod_ocaml.so to your apache libexec directory, e. g. /usr/local/apache/libexec.

Make two entries in your httpd.conf configuration file:

LoadModule mod_ocaml mod_ocaml.so
AddHandler ocaml-parsed .ocml

Restart your apache web server. Now it is ready to process your OCML-files.

Usage

You simply write poor old HTML code and save it under your webserver root. Choose the extension you entered at the "AddHandler" directive in httpd.conf (per default, this is .ocml). So you save a file named, e. g. test.ocml.

Until now, you didn't use any of the mod_ocaml benefits. Try to include OCAML code, and it will be displayed "as is". Since you want your OCAML code to be interpreted and evaluated, you have to inform mod_ocaml of this:

< ?ocml

Printf.printf ("This is generated by the OCAML interpreter.");;

? >

As you can see, the init tag for your OCAML parts is "". As said before: It is much like PHP, but it's OCAML with all its advantages and possibilities of functional and imperative programming. Everything that is located on the outside of these OCAML blocks will be displayed "as is".

This solution makes it also possible to include HTML code within a loop statement like "while" or "for", e. g. when outputting big HTML tables with many cells and columns. But don't forget about the functional focus of OCAML when using things like that ;-)

Interoperability

Sure. You want to process GET requests within your mod_ocaml pages. You call your pages like http://www.some.where/mypage.ocml?a=foo&b=bar. After that, you have two variables a and b which are fully available to your OCAML code. Just include them with $a and $b, like this:

Printf.printf ("$n");;

Please note: YOU (as web developer, programmer, ...) are responsible for proper implementing these external vars, e. g. including in quotation for strings, etc. Also take care of input checking if you're expecting lists and other cool data types from the "outside"

We didn't want to check this external input. Not because we were too lazy, but you shall have all the possibilities to do with mod_ocaml what YOU want. Additionally, OCAML is a typed language and you just have to pay attention to what you are doing. When we set up the concept of mod_ocaml, we didn't want to destroy this intention.

last updated on:
May 5th, 2005, 14:25 GMT
price:
FREE!
homepage:
slacky.de
license type:
GPL (GNU General Public License) 
developed by:
Leo Fellermayr
category:
ROOT \ Internet \ HTTP (WWW)
mod_ocaml
Download Button

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT