Go to the first, previous, next, last section, table of contents.


Introduction

This file doc.sections.tpl, last modified on 2001-01-06.

Without any doubt, OCaml is a great langage for Web publishing. I used it for a long time to produce my static web pages and more recently to write some CGI scripts.

HereDoc is an attempt to provide syntactic sugar for such applications.

In OCaml, strings constants can span multiple lines. Of course, this is most useful for the applications we have in mind. But OCaml lacks some imporant features.

  1. you have to escape every " (the string delimiter in OCaml) in a string; for instance, the produce the string <a href=".."> you have to write <a href=\"...\"> and, believe me, it becomes quickly annoying.
  2. if you want to insert the content of an identifier or the result of a Caml expression (computed value), you have to do things like :
    1. print_string ("The value of x is " ^ x ^ ".");
      
    2. Printf.printf "The value of x is %s." x;
      
    In Perl and similar languages, you just write :
      print "The value of x is $x.";
      
    which looks nicer.
  3. there is no easy way to include file, at compile time. We would like to include files verbatim or use them as templates (text with gaps to be filled).

HereDoc relies on Camlp4, the powerful preprocessor for OCaml, to extend the concrete syntax of the language and provide convenient notations for all these operations. Most of the work is done at compile time, so the code is fast.


Go to the first, previous, next, last section, table of contents.