Developing Applications With Objective Caml
The Book The book itself is quite comprehensive, clocking in at over 700 pages and covering material ranging from an introduction to the language to concurrent and distributed programming. To organize all of this material, the book is broken into four main sections that build upon each other. Each section has a set of chapters that present some related concepts, followed by an "Applications" chapter that uses those concepts to create a few small applications such as a minesweeper game, a graphical interface library, a couple of different two-player games, a distributed robot simulation, and a basic HTTP servlet. These four sections are as follows:
I. Language Core
This section serves primarily as an introduction to the OCaml language, with chapters on the functional core and imperative aspects of the language, a chapter on the differences between the two styles that shows how the two can be melded, and a chapter on the OCaml Graphics module. The introduction to OCaml is complete enough that anyone with a background in programming should be able to achieve a good understanding of the basics of the language. Especially when combined with other freely available resources, like Jason Hickey's Introduction to Objective Caml , and Richard Jones' Learning OCaml for C, C++, Perl and Java programmers, one should be able to obtain a strong OCaml foundation to use while reading the rest of this book.
II. Development Tools
The second section covers, as the title states, the OCaml development tools. The chapters in this section provide information on the OCaml compilers, interpreter, and interactive toplevel environment; some of the libraries included with the standard distribution; OCaml's garbage collection mechanism; Ocaml's debugging and profiling tools; OCaml's versions of lex and yacc; and interfacing OCaml with C. This is perhaps the most valuable section of the book, as it provides good coverage of some important topics that are covered a bit too briefly in the OCaml manual.
III. Application Structure
This section covers the OCaml Module system, and its interface and functor (parameterized module) facilities. Also included in this section is a well written chapter on object oriented programming in OCaml, and a chapter comparing the two models of program organization, offering a brief look at how the two systems can be combined to reap the benefits of both.
IV. Concurrency and Distribution
The final section covers the topics that many folks might consider to be the "real world" programming topics: File I/O, process management and communication, concurrent programming using threads, and distributed programming. The coverage in this section is, again, well done, but perhaps a bit light, and it would have been nice to see more time spent on this subject matter. However, the book is already quite hefty, and the services provided by OCaml's Unix module should look familiar enough to most programmers that the material that is presented should be sufficient to get a competent programmer up and running.
The Upshot For the most part, Developing Applications With Objective Caml does a very good job at presenting the OCaml language in more of a "practical" light than other books on languages in the ML family (and functional languages in general). And while the applications that are constructed throughout this book aren't anything particularly great or interesting in and of themselves (a simple BASIC interpreter, a rudimentary database, a client-server toolbox, etc.), they aren't the primary purpose of the book. What the applications are used for is to illustrate how the concepts presented earlier in the book are used in within the framework of an application, and not just as isolated examples. This is especially important, as most people who might read the book will be unfamiliar not just with Objective Caml, but with the entire functional programming paradigm. Repeated exposure to working OCaml code helps to familiarize the reader with functional programming and OCaml idioms while reinforcing the book's material.
There are, of course, some problems with the book. For one thing, Developing Applications is nearly five years old, half a lifetime when dealing with most computer related topics. This issue is first brought to light in the introduction where it's mentioned that chapter one tells how to install version 2.04 (OCaml is currently at version 3.08), and then in chapter one, when the reader is warned that, "Objective Caml only works under recent versions of Windows : Windows 95, 98 and NT." Fortunately, the information presented about the language remains valid (and Appendix B presents some of the features added to the language by version 3.04, the release that was current at the time of the translation). There are also a few spots where the code in the book contains minor errors, but both of these issues can easily be overcome with the help of the resources listed earlier in this review, or with the help of the OCaml community. Other minor issues crop up as a result of the translation, with the occasional odd sounding phrase popping up in the text and examples. These problems are, however, few and far between and do little to detract from the material or the presentation. And so this book still remains one of the best resources for learning Objective Caml. I used it when I was learning the language, and I still turn to it from time to time as a useful resource.
Will the book turn you into an OCaml guru, or teach you all sorts of advanced type system trickery? No, of course not. But it can teach you enough about the language to start you writing real apps in it. And it will allow you to add a fast, flexible, and powerful language to your toolbox.
Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Possibly the most widely used app written in Objective Caml -- MLDonkey
Why just last week I was developing applications with an Opinionated Camel, and it was hell.
Hell, I tell ya.
If you don't know what AltaVista is (was), get off my lawn.
Yes, I've been intrigued by OCaml for a long time.
OCaml's major problem is that, like every other functional language available today, the breadth of its standard library and third-party libraries is totally pathetic in comparison to the likes of Java and Python. The same limitation applies to Lisp, Scheme, Haskell, Erlang, etc.
These languages face a Catch-22: until they're more popular, they won't attract enough developers to ameliorate the library situation, yet until they offer better libraries, they won't attract developers. Historically, this barrier has been surmounted in one of two ways: either a deep-pocketed corporation subsidizes library development until the language gains momentum (see Java, C#) or the languages are sufficiently "charming"/"hip" that the library support appears as a result of a grass-roots effort (see Perl, Python).
Is there any realistic prospect that one of the functional languages I mentioned will strike it rich in either of those ways? It doesn't seem likely to me.
Erlang.org: wow
No. Next?
What, me worry?
But didn't have a project on hand to try coding in Ocaml with. To be honest I found it hard to kick my brain into the rather different gear that OCaml requires (though I have done a little Lisp programming, I haven't had too much experience in real functional languages). Without an example to work on yourself, and understand quite how to structure things I think it can be hard going. I just didn't have the time to commit properly, unfortunately. What I did see of the language was truly impressive, and this book certainly sounds like an excellent resource. Maybe it's time to go back and try again.
Jedidiah.
Craft Beer Programming T-shirts
_
.--' | .--. /` '. /\| /'----`\ /
//_( //_(
/___^ |
) | / \
/ |
| '-' / \
\ | |\
\ / \
\
||| \\ |
((| ((|
||| |||
Important Stuff
# Please try to keep posts on topic.
# Try to reply to other people's comments instead of starting new threads.
# Read other people's messages before posting your own to avoid simply duplicating what has already been said.
# Use a clear subject that describes what your message is about.
# Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page)
Problems regarding accounts or comment posting should be sent to CowboyNeal.
I'm a Ruby zealot myself, but this comment was the most off-topic ever seen on /.! I know nothing about OCaml (I learn Scheme now) and I'd prefer REAL opinion from real OCaml guys...
:D
Wow, and K&R's ANSI C is like over ten years old - C must be like so shit, no wonder no-one uses it!!! God bless a language that needs its goalposts moving every year. Yes, I want to spend more time learning how to use my tool than actually using it.
OCaml code can rival C++ code in benchmarks...if you write OCaml that looks like C++. Yes, the OCaml code is still probably safer in the end, but the OCaml solutions to many of the benchmarks are just nasty. The prettier, straightforward solution is often 2-4x slower than the C++ version. So is OCaml fast? Yes. But please be careful here.
Isn't saying, "OCaml also has full support for object-oriented programming that fits in completely with OCaml's strong type system." equivalent to saying, "Ford Thunderbird also has full support for all fuels that meet its fuel requirements."?
"This signature quote intentionally left blank"
Contains subliminal likeness of goatse "giver".
This is where .net and mono could do a difference. They allow any language to be used with each other. So get your favorite functional language compiled for .net and you instantly have the whole library.
But despite this and this, as far as I can see there have not been any massive worldwide shifts toward functional programming recently.
I guess it's hard to change.
One way is to find a niche and just nail it. Be the best thing out there for it. PHP did that, and if they play their cards right, they could grow out of that niche too, surpassing things like Python in popularity, even if PHP isn't that beautiful a language.
To really understand this problem, you are going to have to read *gasp* marketing and economics books. "Crossing the Chasm" and "Information Rules" (network effects, lock-in, and so on) are ones I find interesting. I've heard "the innovator's dilemma" is good too, but haven't read it yet.
http://www.welton.it/davidw/
I think FFTW would be the most famous and useful if not the most popular.
At first read I thought it said "Developing Applications With Objective Calm" -- which, come to think of it, would probably make for a pretty interesting article.
The article was about Objective Caml. Parent post was directly talking about Objective Caml. No way is that offopic.
I think some moderators are letting their anti-Korean prejudices show when in fact we could learn a lot from the people of Korea. In Korea, these sorts of prejudices are only for old people.
Does this count the same as anyone from GNAA?
Or because it's CAML, will it be allowed? Please tell me what to flame!
In Korea, only old people use scripted languages.
Buffy and especially Willow/Tara fans know what I mean.
Someone's pet hobby horse. Perl is bad enough.
I looked everywhere. None are intuitive and easy like the java.sun.com tutorial.
I downloaded the compiler about a year ago but got turned off by the quality of tutorials.
You need easier reading material if you want people to adopt.
Damn company only lets me smoke 'em outside though.
I am a big fan of Ruby either.
I use Ruby for scripting exclusively, but my experience is that dynamically typed programming languages are not suited for larger projects, since they tend to have a lot of runtime errors, and very sensible to changes in compiler version.
The file synchronisation tool unison shows that OCaml is exteremely well suited for complex file-manipulation algorithms.
I can relate to that. Centum has the same problem ... how can I attract talented developers to write libraries when talented developers usually only work with languages that provide them with the libraries they need?
Philosophy.
This was my opinion at first. My first OCaml program (a simple fractal computation algorithm) was about 20 lines long and it took me a whole afternoon and it was no fun at all. After I got used to that syntax I learned to like it, and now I really prefer to almost any other languagues (expect for Ruby). I always prefered it over LISP, since the lot of parenthesis makes it too uniform and therfore hard to read.
My first o'caml script:
o
oooo o
ooooo o oooo
o o o o
o o oo oo
o ooo o o
o o oo
o o o ooo
o oooooooo o
ooo oo o
ooo ooo
ooo ooo
oooo oooo
Lameness filter encountered.
Your comment violated the "postercomment" compression filter. Try less whitespace and/or less repetition. Comment aborted.
Important Stuff
# Please try to keep posts on topic.
# Try to reply to other people's comments instead of starting new threads.
# Read other people's messages before posting your own to avoid simply duplicating what has already been said.
# Use a clear subject that describes what your message is about.
# Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page)
Problems regarding accounts or comment posting should be sent to CowboyNeal.
God is slashdots compression filter is retarded..
sik0fewl Preferences Subscribe Journal Logout Sections ain ApacheApple AskSlashdot 1 more Books BSD 2 more evelopers 1 more Games 11 more Interviews IT 4 ore Linux 1 more Politics Science 3 more YRO 2 ore Help FAQ Bugs Stories Old Stories Old Polls opics Hall of Fame Submit Story About Supporters ode Awards Services Broadband PriceGrabber ProductGuide Special Offers Tech Jobs IT Research
I remember when legal used to mean lawful, now it means some kind of loophole. - Leo Kessler
We saw from the examples that the typing in C and Pascal failed for several reasons. It was too fine-grained, as in Pascal's useless distinction between an array of twelve characters and an array of thirteen characters. It led to many spurious error messages, which means warnings that are ignored and waste everyone's time. It was too easy to violate the type systems though union types and casts, and it had to be so, because of the preponderance of spurious errors.
Can't we give this one a rest? Has anyone run into s:array[1..20] of char being incompatible with s:='Foo'; since the 1970s?
I feel like I get slightly stupider out of empathy every time I read about that.
Are there any good websites for how to learn a functional programming language that are devoted strictly to people who are experienced in normal programming languages?
(Sorry for the use of the word 'normal'. I don't mean anything untoward by that)
If you add to the list of features the ability to compile to C source and the support for multiple inheritance then you get Eiffel. The lack of strongly typed extensive base library seems to a problem with Eiffel too.
If I am fluent in C++ (powerful), Java (run anywhere) and Ruby (scripting), what advantage does this new language have over those? What problems will this new language solve? If it's one of those above, how is this one better than the language I'm already using? I'm all for learning a new language for fun, but for work I'd better have a good reason for putting out the effort.
I've also written an OCaml tutorial for people coming from 'conventional' languages like C, Perl and Java.
Rich.
libguestfs - tools for accessing and modifying virtual machine disk images
Here is a beautiful derivative of prolog in desparate need of an o'reilly treatment.
the manual pdf at the link was way over my head.
I guess I am no computer science major because it was difficult reading.
That's one of the hopes behind a common multiple-language (polyglot ?) virtual nachine like parrot.
Parrot will support big language like Python and Perl6.
Bindings and libraries will be written for python-vm but could be used from within any language that supports parrot as target.
Then you could use or create whatever language you like. As long as it targets parrot, all parrot bindings and libraries will be available to your scripts, even if the libraries aren't written in you language but with some other language supported by parrot.
Maybe once parrot reaches more stable and mature stages in a couple of years, we may see the advent of a lot of small special purpose scripting languages. Developpers won't be affraid to invent some highly specific language for their application, because users will be able to re-use libraries done for other languages.
Imagine a Parrot-enabled console in Quake V or Doom VI, and you could try using some AI modules in parrot bytecode format from some MOD for Unreal 2009 (or Duke Nukem 4 if there's the slightest chance it ever comes out by then... )
"Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
I've been using this as a reference since college. This has been out for years.
If you can't see the structure for the parens, you need an editor.
Try Corewar @ www.koth.org - rec.games.corewar
huh. I find the lot of parentheses in lisp make the syntax uniform enough to comfortably read. But hey, I like forth and APL syntax too. Small number of rules. I DETEST C++ syntax, and don't like "idiomatic" perl or ocaml (while it is possible to write your own code fairly regularly in either, most of your time as a programmer is spent reading other people's code, and other people's perl or ocaml sucks).
In this talk appears the quotation:
Which made me physically shudder. What could these ancient horrors look like? Could anyone post a link to some of this ancient and offensive code? I mean I've written code for school if a group member has used *a* goto. This is something I need to see.
Your CPU is not doing anything else, at least do something.
I was getting into OCaml a while back, to the point where I wanted to replace my extant software with OCaml rewrites, and then someone pointed something out to me: OCaml has an annoyingly onerous license. You aren't allowed to distribute, fork, change, or anything the main OCaml source. How annoying!
OCAML is a great language. Unfortunately, despite its excellent performance on many benchmarks, OCAML performance on common kinds of numerical or graphics code is still lacking.
Basically, if you can't write a complex FFT with a user-defined complex number type and have it work about as efficiently (in both space and time) as equivalent Fortran 90 or C++ code, then the language is not suitable for modern general-purpose applications. Java fails this test, too. Among commonly used modern languages, C++, C#, and Fortran 90 pass that test.
http://groups.google.com/groups?hl=en&lr=&threadm
OCaml/Caml is worse, worse, worse than the rival Common Lisp when it's supporting intensive memory's applications.
Have I to rewrite Caml-II-0.7?
Noooooo!!! Arghhhh!!! I've not time!!!
open4free ©
"OCAML is a great language. Unfortunately, despite its excellent performance on many benchmarks, OCAML performance on common kinds of numerical or graphics code is still lacking."
Well I guess that means we can write Slashdot in it.
This is getting off-topic, but maybe this is more a reflection on your coding technique than on dynamically-typed languages?
Annecdotal evidence abounds for all sorts of claims concerning static vs. dynamic typing. My experience is just the opposite of yours.
More specifically, if you are writing anything larger than one-off admin scripts then your code should have unit tests. And proper unit tests will catch the odd runtime error you might otherwise see in the wild. They'll also catch the cast exceptions and null pointer exceptions that still plague statically-typed languages. Merely passing a compilation stage, regardless of the typing system, is no assurance of robust code.
Java is the blue pill
Choose the red pill
I'm not sure how you could refute the official objective caml license, which clearly states that runtime system and standard libraries are licensed under LGPL (to allow linking with commercial programs), and the compiler and tools are licensed under QPL, which allow you to distribute unmodified code as is, or your modification "in a form that is separate from the Software."
The example given in QPL is using patches, but I don't see why you can't fork the source, since it would still be "separate" (just don't call it Objective CAML, but something else). QPL does not say your modification has to be in the form of patches.
I once had a signature.
I thought that all you geeks were supposed to be more rational than that. What is with all this cult-of-personality bullshit.
oh well, if we must have a figurehead, why not Natalie Portman? I mean, honestly...
I initally used thebook as a resource for learning Ocaml. My review would be more like:
Language Core
This covers the basics of the language, although the presentation of material is somewhat disjointed, which makes the book challenging to use as a reference in the first programming steps.
The book is clearly a translation, and in some areas the translation is not especially literate, although the meaning of the text is always pretty clear.
The worst problem with the book is that it is severely out of date with respect to the latest distribution of Ocaml. The aspect that had me tearing my hair out was the lack of coverage of open types - something which is essential to using a GUI toolkit, and which is somewhat complex as there are rules which may come as slightly odd to those used to the implementation of polymorphism in other languages.
Development tools
This section gives a good overview of many of the tools available, and is probably the best part of the book. The major ommission is Ocamlp4, which, again, post-dates the book's authorship. Users on Windows (bow your heads in shame... this is Slashdot) will find that their platform is not really covered, which is a shame, as there are a few differences from Windows.
The rest
Coverage of libraries is way out of date. For a modern user, the only serious GUI choice is LablGtk2, and it is not covered at all. There are other problems in a similar vein.
The book contains a number of extended examples. While these smack of being 'undergraduate projects', they do indicate some of the techniques and paradigms of programming in Ocaml.
ConclusionI wouldn't recommend this book. It's too far out of date (imagine buying a book on Perl 4 or Python 1.5). Since the Ocaml manuals are quite comprehensive, and there's an excellent tutorial at merjis.com, which is fast paced and does cover modern language features, there's really no need for this without a significant update. Sorry.
Well then you'll be pleased to know that Ocaml comes, thanks to its camlp4 preprocessor, with three different syntaxes : the standard, the revised, and... Scheme syntax, using pr_scheme.cmo.
OK OK flamebait, troll, whatever... but I still don't see the point of having a very small niché language messing around open source projects... i've seen a sourceforge project that have a part written in Ocaml, and their dependance on a very small language which very few people know about, is stalling the project big time.
Maybe Ocaml is the heck of a development language, but I think it's about 5 years late...
my 2 cents.
I develop in a range of languages, but mostly Java for its cross-platform-ness and GUIs, and Python for its clear syntax.
If i had a combination of the two - python's pureness and cleanliness and Java's x-platform libraries - i would be pretty happy. However, i would still be stuck with Swing for GUI work.
I would like to see a language that is built for creating rich GUIs, and have it be as clean and simple as Python, and as well thought out as InterfaceBuilder (OS X).
Java/Swing (and TCL/TK is surely worse) still requires one to write lots of boring code that should be handled by the framework. In addition, Swing has a huge problem with allowing needlessly many options in implementing common things (and, again, doesn't implement them to begin with) so if you read somebody else's code, chances are they did everything completely differently. There are no design guidelines, and even Sun's code is not consistent in any way.
O'Caml may be better at some things and in some way than Java or Python, but unless a fantastic GUI framework is included, it's not that interesting.
Microsoft is working on a language based on oCaml, called F#
Why use Ocaml? the question has been raised before. Should I use it for being functional? but functional programming has practical issues.
For example, sorting with functional languages is very very slow, since lists are copied over and over, and for each sorted element, a new list is created. For example, the quicksort algorithm takes each element of the input list, then splits the rest of the list to less than the element and greater than the element lists, sorts these lists and then combines the three parts (the less than part, the element and the greater than part) into the result. It may be only a few lines of code, it may be much clearer than the imperative way, but it is much too slower for practical use.
So, what advantages Ocaml has over traditional imperative languages like C++ or Java when its functional characteristics are not to be used?
Why is this modded funny? Should be interesting or insightful. Lots of posts here are being modded funny when they shouldn't be...
Along with his cousin O'Bject?
#read_expression "x-1";;
Exception: You don't want to be reading from that stream you don't lad, no, that ya don't...
It's a popular advice (wisdom) that to be a good
...
programmer one needs to learn a new programming
language every now and then.
Also another good and popular advice that a programmer
should introduce himself to many programming paradigms
like OOP, AOP, Procedural, Static, Dynamic, Generic, Strongly typed, Weakly typed, Un-typed, etc
I think choosing to learn O'caml achieves both advices.
So in other words, you might want to learn O'caml, not just because it's a good language, but because by learning O'caml you might become a better programmer!
The function named 'repeated' takes two arguments. In OCaml, parentheses are not used to surround arguments as they are in C. Instead, they are used to surround tuples, similar to the way braces are used to surround literal arrays in C. Translating the example into C syntax: /* The function takes two arguments */ /* Wrong: only one argument is passed */ /* Right: two arguments are passed */
void repeated (int a, int b);
repeated ({123, 456});
repeated (123, 456);
In the first example the function is called with one argument which is a structure of two elements. Putting parentheses around arguments in OCaml is like putting braces around them in C - it groups them into a single argument.
But then, what were you expecting?
We'll charge the mod with MUI.
I know that. But now get every other OCAML programmer to use it. Idiomatic OCAML examples are in its baroque monstrosity syntax, not the clean one.
Xavier Leroy, the main designer of the language, definitely has the charism and the technical authority to fit that role. Unfortunately, he is not interested in this, as Objective Caml is, first and foremost, a research tool for him and the other members of INRIA.
He is committed to creating the best possible language, not in adding tons of features, and I think he has succeeded so far in this endeavour. However, he and his team are very careful to keep control on the development of the language and are not very keen in including the works made by the community. For instanfe, there are interesting libraries developed by the community which, imho, ought to belong to the standard lib, but aren't.
This attitude is quite discouraging. Still, the community is slowly organizing itself around a distribution called GODI which aims to be the ocaml CPAN.
Clean is a very powerful language and also comes with a very efficient native code compiler. Slightly less fast than Ocaml, but a vey expressive language.
Could Ocaml be a serious alternative to Fortran for scientific/technical computing?