caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Ocaml server pages?
Date: Sun, 3 Oct 2004 21:45:14 +0100	[thread overview]
Message-ID: <20041003204514.GA2983@annexia.org> (raw)
In-Reply-To: <001b01c4a7e0$fbaf7770$ef01a8c0@warp>

[-- Attachment #1: Type: text/plain, Size: 4779 bytes --]

On Fri, Oct 01, 2004 at 08:03:39PM +0200, Nicolas Cannasse wrote:
> > Note that there are at least 4 different ways to do web stuff with
> > OCaml, all with their own pros and cons.  At some point I intend to
> > write up a summary, but in the meantime, here are the three (other)
> > packages in no particular order.  You can go to their web pages and
> > read about them:
> 
> Could you quickly sum up theses differences for this list readers ?
> I'm recently interested in high level server side languages.
> Any hint to show me what's "best" is apprecied.

I'm not going to claim that any of the four approaches is best, but I
will try to summarise them as far as my understanding goes.  Please
don't flame me too much for this; and do also note that I am the
author of mod_caml.

** mod_caml

mod_caml sits inside the Apache process, and its strengths and
limitations derive from this fact.  Because it's inside the process,
it has full access to the Apache API, which means that you can, for
example, make subrequests, or write an authentication handler, or
write a more sane URL mapping system than mod_rewrite, or [coming
soon, with Apache 2.0] use OCaml code to post-process the output of
some other CGI script written in another language.

It's completely tied to Apache.  You have no other webserver choice
once you've decided to use mod_caml.

Apache preforks itself, so there are actually several instances of
your code running, in separate processes, all working on separate HTTP
requests.

Because it uses Dynlink to load code, you can only use bytecode.  (I
would argue that most web applications are heavily IO bound, so this
isn't a problem.  But I can certainly imagine some compute-intensive
application, or part of an application, where the lack of native
compilation would be a serious shortcoming).

It doesn't use Gerd's Netcgi module, but instead uses its own which is
basically a reimplementation of Perl's Cgi.pm in OCaml.  This is good
news for ex-Perl refugees like me, of course.  mod_caml itself is
independent of ocamlnet, but I personally use quite a lot of ocamlnet
functions.  The 2.0 release of COCANWIKI will depend on ocamlnet for
URL parsing, generating and parsing MIME emails, and maybe other
stuff.

It comes with a template library to enforce correct separation of code
and HTML.  You can see this in action by grabbing the COCANWIKI 1.0
distribution from http://sandbox.merjis.com/ and comparing the
scripts/ and templates/ directories.

** ocamlnet & asxcaml

ocamlnet runs outside the web server, using either FastCGI or JSERV to
communicate with the web server.  (Or you can run your scripts as
ordinary CGI external programs, but I wouldn't recommend that for
serious use).  Your program is linked together into a single binary
which, when started, is a FastCGI or JSERV server, and processes
requests either sequentially or by forking a new process for each
request.  The webserver then acts as a proxy between the browser and
your program.

There are two important consequences of this: (1) You can use native
code. (2) Your whole program is compiled together a single unit.

There's no templating or database access, but you could easily add
these by using mod_caml's templating system or CamlTemplate, and
ocamldbi respectively.

AS/XCaml is built on top of ocamlnet, and I'm not going to claim to
fully understand it or even to have used it.  However the big feature
is the statically typed SQL implementation.  This is a big improvement
over ocamldbi (which can throw type errors at runtime if your database
returns a field with an unexpected type).  The reason I didn't do this
for ocamldbi was because it would involve fully parsing every variant
of SQL and/or limiting the complexity of SQL queries permitted.
AS/XCaml uses an XML file to describe your database schema, and from
this (I'm guessing) derives the schema and queries.  In concept this
is very similar to PDL
[http://www.redhat.com/docs/manuals/waf/rhea-dg-waf-en-6.1/s1-pers-pdl.html].

** mod_ocaml

This is another Apache module.  It's similar in concept to JSP or PHP.
You actually embed OCaml code into your webpage.  The webpage is then
compiled (with ocamlc) and run on the fly.  Your OCaml code prints
HTML.

Having worked in a professional web applications outfit for a few
years, I can't in all conscience recommend embedding code into web
pages which designers might try to edit.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Learning Objective CAML for C, C++, Perl and Java programmers:
http://www.merjis.com/richj/computers/ocaml/tutorial/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2004-10-03 20:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-01 15:50 Charles Sutton
2004-10-01 16:04 ` Richard Jones
2004-10-01 18:03   ` Nicolas Cannasse
2004-10-03 20:45     ` Richard Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041003204514.GA2983@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).