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."

5 of 43 comments (clear)

  1. Improved linkage by fm6 · · Score: 4, Informative
    The link to Bagley.org gets diverted because Doug Bagley is a Slashdot-hater. You can read his summary of CAML by cutting and pasting
    http://www.bagley.org/~doug/shootout/
    into your address bar.

    Since CAML is a functional language, it's probably more productive to compare it with other functional languages than with more familiar procedural languages. Good stuff here and here. In this context, it makes sense to have a particular look at Guile, which is like mod_caml in that it implements a functional language as a means of writing application extensions.

  2. 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

  3. Re:O'Caml for Scripting? by Richard+W.M.+Jones · · Score: 4, Informative
    I've tried to make mod_caml "scripting"[1] as simple as possible. There's a few example scripts in the manual here:

    http://www.merjis.com/developers/mod_caml/docs.sht ml

    Where possible I've gone for reducing the amount of code that you have to write in the common cases, based on a large amount of experience writing CGI scripts in Perl.

    At the moment we're missing a fully integrated database layer, but that's coming soon (the code is already out there, I just need to pull it in and do the persistent database connection stuff).

    Unfortunately I only get to work on this at weekends, but hope to have a Savannah page up soon so others can more easily contribute.

    Rich.

    [1] It's not really "scripting" as such. OCaml programs are bytecode compiled and dynamically linked into the bytecode interpreter which runs inside Apache. We also hope to get natively compiled loading working at some point.

  4. Not tail-recursive by r6144 · · Score: 3, Funny
    Here is a tail-recursive version:
    let process_line () =
    try let s = read_line () in
    (true, 1,
    List.length (Str.split (Str.regexp "[ \t]+") s),
    (String.length s) + 1)
    with End_of_file -> (false, 0, 0, 0)
    ;;

    let rec wc (lines, words, chars) =
    match process_line () with
    (true, l, w, c) -> wc (lines + l, words + w, chars + c)
    | (false, _, _, _) -> (lines, words, chars)
    ;;
    let lines, words, chars = wc (0, 0, 0) in
    Printf.printf "%d %d %d\n" lines words chars
    ;;
  5. Re:O'Caml for Scripting? by smallpaul · · Score: 4, Informative

    Only in a very limited sense could Python be considered strong typing. It's stronger than C, but most anything is

    There are a variety of languages that allow you to cast raw memory addresses to whatever you like: C, C++, Forth, Assembly language, many basics, etc. Those are weakly typed languages as the term was originally applied. Python is a strongly, dynamically typed language. And object has exactly one type and you cannot convince it to behave as another type merely by asserting it is that other type. When you try to get a Python object to do something disallowed by its type, you get an exception whereas in the languages described earlier the results are undefined.