![Programming Programming](http://a.fsdn.com/sd/topics/programming_64.png)
![Software Software](http://a.fsdn.com/sd/topics/software_64.png)
![Apache Apache](http://a.fsdn.com/sd/topics/apache_64.png)
![IT IT](http://a.fsdn.com/sd/topics/it_64.png)
![Technology Technology](http://a.fsdn.com/sd/topics/technology_64.png)
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."
Old caml page (Score:2, Informative)
I've noticed that the home page [ocaml.org] is kind of slow. There's the original, old one at INRIA [inria.fr].
HTH
Re:Mod gradparent up! (Score:1, Informative)
Caml is the best language ever: Take a look
at the annual programming language results
for Ocaml:
ICFP'02 (1st prize)
ICFP'01 (3rd prize)
ICFP'00 (1st prize)
ICFP'00 (2nd prize)
ICFP'99 (1st prize)
ICFP'98 (2nd prize)
C++ and Java never won anything, even
though there are always many more C++ and
Java contestants than OCaml ones.
Re:Mod gradparent up! (Score:2)
That being said, OCaml is a great language, and I've been hacking in it for the last 5 days straight. It's gotten so that I hate programming in Java (too verbose, and inflexable) and Perl (Datastructures designed to inspire disgust.. I find myself writing $#{$categories} in my code and I want to cry)
Go OCAML. w00t!
O'Caml for Scripting? (Score:1, Interesting)
Re:O'Caml for Scripting? (Score:2)
worst troll ever
Re:O'Caml for Scripting? (Score:2)
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.
Re:O'Caml for Scripting? (Score:3, Interesting)
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.
Re:O'Caml for Scripting? (Score:5, 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.
Re:O'Caml for Scripting? (Score:2)
Python is a strongly typed, dynamically typed language. That means that you can do:
but something like
gives you a type error.
Old-style Perl and K&R C are weakly typed becau
Re:O'Caml for Scripting? (Score:2)
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
Re:O'Caml for Scripting? (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:
Sorry for the ugly formatting, but Slash is unforgiving
Re:O'Caml for Scripting? (Score:1)
You're right on all three counts, atlhough I'd rather use HTML. I've corrected the program; for anyone interested, it is in here [paginar.net].
Compiled with ocamlopt -o ocwc ocwc.ml, I got these results:
I think it's pretty decent.
Re:O'Caml for Scripting? (Score:1, Informative)
Christ, that's "good for scripting"? Here's a Ruby version:
I'd call a language like that "good for scripting". Doesn't get in your way.
Re:O'Caml for Scripting? (Score:1, Informative)
open Str
let (+=) r i = r
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
Re:O'Caml for Scripting? (Score:1)
Not tail-recursive (Score:4, Funny)
Re:O'Caml for Scripting? (Score:2, Informative)
let lines, words, chars = ref 0, ref 0, ref 0 in
Pcre.foreach_line (fun line ->
incr lines;
words
chars
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
Re:O'Caml for Scripting? (Score:1)
Re:O'Caml for Scripting? (Score:1)
Re:O'Caml for Scripting? (Score:5, Informative)
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.
Re:O'Caml for Scripting? (Score:2)
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?
Re:O'Caml for Scripting? (Score:2)
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.
Re:O'Caml for Scripting? (Score:2)
Re:O'Caml for Scripting? (Score:3, Informative)
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
Re:O'Caml for Scripting? (Score:3, Interesting)
CamlLoad /path/to/my/module.cmo
Then all scripts can access functions/values in Module.
Rich.
Improved linkage (Score:5, Informative)
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)
Re:Improved linkage (Score:1, Funny)
I don't know why you'd t
Re:Improved linkage (Score:2)
Re:Improved linkage (Score:3, Interesting)
So far, no worries on that point.
Re:Improved linkage (Score:3, Insightful)
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
Re:Improved linkage (Score:1)
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 really interesting! Good (Score:1)