Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Programming Software Apache IT Technology

mod_caml Comes Of Age 43

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."
This discussion has been archived. No new comments can be posted.

mod_caml Comes Of Age

Comments Filter:
  • Old caml page (Score:2, Informative)

    by notfancy ( 113542 )

    I've noticed that the home page [ocaml.org] is kind of slow. There's the original, old one at INRIA [inria.fr].

    HTH

  • by Anonymous Coward
    i have a question: ocaml is usually only used for "heavy" projects like compilers or proof assistants. however, it should also be a great scripting language. i wonder if other people have used it for this purposes and would like to relay their experiences -- good or bad?
    • What? You don't want strong typing in a scripting language -- for all the differences between Perl and Python, weak typing is one thing they share. (S)ML is my favorite language but I wouldn't use it for scripting.

      worst troll ever

      • Weak != Dynamic.
        Python is strongly, dynamically typed. Perl's is just wierd, I wouldn't call it strong or weak.

        The killer feature of ML derivatives is type inference, which in theory gives you the benefits of declaritve static typing (like C or Java) without the hassle and those of dynamic typing without the uncertainty.
        • Only in a very limited sense could Python be considered strong typing. It's stronger than C, but most anything is, and you can do things like
          obj.feild = 4
          and in general, functions tend to care about whether their arguments have certain properties (you can apply something to them) rather than what type they are.

          And yes, type inference is absolutely necessary to have a workable strong-typing system - otherwise you end up with something as verbose as Java.

          • by smallpaul ( 65919 ) <paul AT prescod DOT net> on Wednesday August 20, 2003 @09:27AM (#6743947)

            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.

          • You're confusing "strongly typed" with "statically typed". Strong vs. weak typing is whether the language allows you to perform type-unsafe operations accidentally. Static vs. dynamic typing is whether the language performs its type checks at compile time or at runtime. All four combinations are possible.

            Python is a strongly typed, dynamically typed language. That means that you can do:

            x = 3; x = "q"

            but something like

            "q" / 3

            gives you a type error.

            Old-style Perl and K&R C are weakly typed becau

      • Actually, I disagree with you. One of the things nice about static typing is that it gives you error messages BEFORE you run your program. Have you ever written a "run-once" perl script that messes everything up because of a runtime error? I have (well, not perl, but elisp), and I think that my bugs would have been caught by SML's static typing.

        I think that perl and python's main offerings are a convenient syntax and easy access to library functions that do the right thing most of the time. SML doesn't hav
    • by notfancy ( 113542 ) <matias@nOSpam.k-bell.com> on Tuesday August 19, 2003 @08:45PM (#6740124) Homepage

      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

      • by Anonymous Coward

        Christ, that's "good for scripting"? Here's a Ruby version:

        lines = words = chars = 0

        while gets
        lines += 1
        words += $_.scan(/\S+/).length
        chars += $_.length
        end

        puts "#{lines} #{words} #{chars}"

        I'd call a language like that "good for scripting". Doesn't get in your way.

        • by Anonymous Coward
          Same in OCaml :

          open Str

          let (+=) r i = r := !r + i

          let lines = ref 0 and words = ref 0 and chars = ref 0

          let _ = try while true do
          let s = read_line () in
          chars += String.length s;
          lines += 1;
          words += List.length (split (regexp "\\( \\)+") s)
          done
          with _ -> Printf.printf "%d %d %d\n" !lines !words !chars
        • by Anonymous Coward
          One can really do better in OCaml for scripting purposes than in the initial version:

          let lines, words, chars = ref 0, ref 0, ref 0 in
          Pcre.foreach_line (fun line ->
          incr lines;
          words := !words + List.length (Pcre.split line);
          chars := !chars + String.length line + 1);
          Printf.printf "%d %d %d\n" !lines !words !chars

          Pcre for OCaml [oefai.at] is a very high-level and efficient string processing library that can do just about anything that Perl offers for string manipulation - only much faster :)
      • LOL, you make ML syntax look even more weird than it is!
    • Using Ocaml as a scripting language as a purpose? Over the years I have come the believe that there is no real distinction in requirements for languages for, what you call "heavy" projects, and scripting. Scripting, according to consensus of opinion, requires an expressive language and generally an interpreter for quick write, run, debug cycles. "Heavy" projects benefit from an expressive language as well. It should be common knowledge by now that the number of bugs per lines of code is constant no matter
    • by Richard W.M. Jones ( 591125 ) <rich@@@annexia...org> on Wednesday August 20, 2003 @03:56AM (#6742052) Homepage
      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 [merjis.com]

      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.


      • It's not really "scripting" as such. OCaml programs are bytecode compiled and dynamically linked into the bytecode interpreter which runs inside Apache.


        Does this mean that each request does not spawn an own process (as CGI usually does) but that the "script" is linked into apache? I mean is this not the way PHP for example works? Do you have an assessment on how much this speeds up the processing compared to CGI?
        • Does this mean that each request does not spawn an own process (as CGI usually does) but that the "script" is linked into apache?

          Yes, that's right. This avoids a fork and the overhead of starting up the bytecode interpreter each time.

          I don't have figures on how much of a speed increase this is, although it undoubtedly has some benefit. However the main reason for doing it is so you can have persistent cached data, and persistent database handles, and that's a much greater win than just avoiding a fork.

          • Persistent cached data? So ocaml values can be instantiated once and then shared for the whole application like with a Java appserver? This is great stuff, I really have to try it out. How far along is it? Does it have any kind of session support or is that up to the application programmer?
            • Persistent cached data? So ocaml values can be instantiated once and then shared for the whole application like with a Java appserver?

              Yes. There's two ways to do this - either just create the value at the top level of the script. Top level functions in a script get called once when the script is first loaded. The run function (which you have to register) gets called on each invocation.

              Thus:

              (* foo is evaluated just once: *)

              let foo = expensive_function ()

              let run r = ... (* generate the page each time

  • Improved linkage (Score:5, Informative)

    by fm6 ( 162816 ) on Tuesday August 19, 2003 @08:16PM (#6739911) Homepage Journal
    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 [nott.ac.uk] and here [wikipedia.org]. In this context, it makes sense to have a particular look at Guile [gnuwww.epfl.ch], which is like mod_caml in that it implements a functional language as a means of writing application extensions.

    • Re:Improved linkage (Score:1, Interesting)

      by Anonymous Coward
      does it really make sense to say that O'Caml is a functional language? clearly it has references and hence is not a pure functional language. it is a mixed paradigm language, like java or c++. in fact, syntactic differences aside, java is a sublanguage of o'caml! hard to believe that o'caml is nevertheless faster than java, but it is ... good work xavier et al!
      • by Anonymous Coward
        Just because Java's slow doesn't make it a mixed paradigm language. While a true mix of functional, list, procedural, logical, and object orientated in a single language, with dynamic interpretation, would indeed be as slow as Java (well, almost as slow), Java manages to be slow without needing to implement so many levels of paradigminity. Using a dynamic object orientation methodology, Java is able to crawl simply by utilizing an ideologically bananas virtual machine architecture.

        I don't know why you'd t

      • "Functional languages" generally means languages that allow for a functional style (having functions as arguments and/or return values of other functions) without much trouble. There are not may pure functional languages like Haskell in widespread use, mainly because you can't do some things as well (e.g. hashing).
    • Re:Improved linkage (Score:3, Interesting)

      by zangdesign ( 462534 )
      I can see his point about hating /. - I read his reasons and they're all reasonable opinions. I pray god I never post anything that is even remotely interesting to /. as a whole.

      So far, no worries on that point.
    • by scrytch ( 9198 )
      > Since CAML is a functional language, it's probably more productive to compare it with other functional languages than with more familiar procedural languages.

      Actually no, it's worth comparing against imperative languages, because caml has those features as well, like fully mutable variables (believe it or not, it's not something you take for granted in the FP world -- erlang's variables are set-once, and haskell has only bindings aside from monad 'do' blocks).

      Ocaml does have several annoying features
      • "You cannot express an unsigned 32 bit int in ocaml."

        module UInt32 =
        struct
        type t = Int64.t
        let zero = 0_L
        let one = 1_L
        let minus_one = 0xffffffff_L
        let neg (n : t) = Int64.sub 0x100000000_L n
        let add (n : t) (m : t) = Int64.logand (Int64.add n m) 0xffffffff_L
        let sub (n : t) (m : t) = Int64.logand (Int64.sub n m) 0xffffffff_L
        (* Etc. *)
        end

        Okay, maybe that comes into the category of "somewhat onerous"...
  • It's simpe and it is great. We write some like this and called it Rejump. www.rejump.com/datafile [rejump.com] Now it's exist only in free version (with some limitation) We have file based database in this one. Does any give some links for similar amusing products? Your are welcome!

"It takes all sorts of in & out-door schooling to get adapted to my kind of fooling" - R. Frost

Working...