Slashdot Mirror


mod_caml Comes Of Age

Richard W.M. Jones writes "mod_caml is a set of bindings between Objective Caml and the full Apache API. mod_caml 0.6 has bindings for the Apache API and a full Perl-like CGI and templating library. There's only two things you need to know about Objective Caml: it's a modern, fully-featured and highly-optimised language, and it has a good tutorial so Perl/Java/C/C++ programmers can join in the fun."

1 of 43 comments (clear)

  1. Re:O'Caml for Scripting? by notfancy · · Score: 5, Informative

    Actually, the procedural elements of OCaml are so strong than, other than syntax (which is more convenient for functional composition than for imperative sequencing), it is an absolute joy to program UN*X-type filters and transformers in it.

    OCaml has a very complete interface to UN*X (including sockets), supports native (POSIX) threading, lots of publicly available libraries exist from regexps to XML parsing, etcetera; so it can be (and is!) used for systems-level programming, much as you would use C or Java.

    The only thing that may put down programmers accustomed to the more forgiving, dynamic nature of scripting languages like Perl is that OCaml's type system is very strict, much more so than Java's. On the other hand, it has type inference, whereas you rarely if ever need to type-declare things (other than for documenting, that is).

    For the sake of example, this is how you would program wc in OCaml:

    type counts = {
    mutable lines: int;
    mutable words: int;
    mutable chars: int;
    }

    let wc fname =
    let inch = open_in fname
    and stat = { lines = 0; words = 0; chars = 0 }
    in begin
    try while true do
    begin
    match input_char inch with
    '\n' -> stat.lines <- stat.lines + 1;
    stat.words <- stat.words + 1
    | '\t'
    | ' ' -> stat.words <- stat.words + 1
    | _ -> ()
    end;
    stat.chars <- stat.chars + 1
    done with End_of_file -> ()
    end;
    close_in inch;
    stat

    Sorry for the ugly formatting, but Slash is unforgiving