Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Programming Books Media Book Reviews Technology

Developing Applications With Objective Caml 243

Fahrenheit 450 (William D. Neumann) writes "Developing Applications With Objective Caml was originally published in French by O'Reilly, and later translated into English by a group of volunteers (note that the reviewer was a volunteer proofreader during the translation effort), and graciously made available online as HTML or PDF at the Caml website. For those not familiar with Objective Caml (or OCaml, as it is commonly called), it is a strongly, statically typed (but don't be thinking about Pascal-style typing), eagerly evaluated language with a functional core that also offers many imperative programming features. OCaml also has full support for object-oriented programming that fits in completely with OCaml's strong type system. On top of that, OCaml code can be interpreted for simple scripting, compiled to bytecode for portability, or compiled to native code for speed and resource utilization that rival even that of Intel's C++ compiler. Intrigued?" If so, read on for the rest of Neumann's review.
Developing Applications With Objective Caml
author Emmanuel Challoux, Pascal Manoury, and Bruno Pagano
pages 742
publisher O'Reilly France
rating 8/10
reviewer William D. Neumann
ISBN 2841771210
summary A comprehensive book on Objective Caml, covering not only the core language, but also modules, objects and classes, threads and systems programming, and interoperability with C.

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.

This discussion has been archived. No new comments can be posted.

Developing Applications With Objective Caml

Comments Filter:
  • MLDonkey (Score:4, Informative)

    by Megaslow ( 694447 ) * on Tuesday November 30, 2004 @06:12PM (#10957367) Homepage
    Possibly the most widely used app written in Objective Caml -- MLDonkey [nongnu.org]
  • Full Support? (Score:3, Informative)

    by engywook ( 802813 ) on Tuesday November 30, 2004 @06:36PM (#10957619) Homepage
    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."?
  • Re:Intrigued? (Score:5, Informative)

    by Anonymous Coward on Tuesday November 30, 2004 @06:39PM (#10957645)
    Well, that may have been true five or ten years ago, but have you checked the Caml humps http://caml.inria.fr/humps/ recently ?

    For GUI you have Tk, GTK, GTK2 ; some people have written interfaces to the Win32 API. Concerning data structures, the standard library has lots (lists, hashtables, queues, sets, maps), and if that's not enough, you name it, you have it (from splay trees to bitvectors), and not only esoteric data structures available only in functional languages. With Bigarray you can MMap huge arrays of whatever you want (bytes, floats). With the built-in lazy streams you can easily hack a LL parser, and if that's not enough you can run ocamlyacc. There are interfaces for Postgresql, mysql. Unix support is very complete (and portable). There is a good crypto library. For number-crunching you have the built-in number library, GMP bindings or numerix. Interfacing to C is excellent. I mean, come on, Perl and Java have, today, more in their libraries, but you really can't call Ocaml's library support "pathetic". Ocaml can and is really used for real apps (Coq, MLDonkey, etc.) with real GUIs. You can't say the same for Scheme. Plus, Ocaml compiles to machine code on i386, PowerPC and a few other architectures, and that runs damn fast even if you don't spend the afternoon optimizing your code.
  • by drafalski ( 232178 ) on Tuesday November 30, 2004 @06:40PM (#10957653)
    I had a "types and programming languages" (graduate level) course at UPenn that made heavy use of OCaml. Though I can't imagine voluntarily going through that material, the resources page [upenn.edu] gives a good general background including OCaml references. The homework page [upenn.edu] provides some OCaml programming examples. The solutions seem to have been pulled, but I imagine they are still easily found on archive.org (which is not responding for me right now to check) or via google.
  • Re:Intrigued? (Score:5, Informative)

    by srussell ( 39342 ) on Tuesday November 30, 2004 @06:44PM (#10957690) Homepage Journal
    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.

    I don't know; I've always been able to find libraries that I needed for Haskell; there are quite a few listed on the Haskell libraries [haskell.org] page. It seemed to me, when I was evaluating OCaml, that a lack of libraries bindings or bindings to other language's libraries was not a problem. They've got quite a decent database of extensions at The Camel Humps [inria.fr]

    I'm mainly a Java and Ruby developer, though, so I may not have stressed tested the availability of Haskell libraries. Java doesn't use libraries; if somebody writes a third-party library for it, Sun re-implements it, poorly, and bundles it with the VM, which effectively kills the original, and often superior, library. And Ruby... well, you just create whatever bindings you need, dynamically, with 'dl'.

    --- SER

  • Re:MLDonkey (Score:3, Informative)

    by bcrowell ( 177657 ) on Tuesday November 30, 2004 @06:44PM (#10957692) Homepage
    Also unison [upenn.edu], which is a great app.
  • by Anonymous Coward on Tuesday November 30, 2004 @07:26PM (#10958164)
    I've learned Caml literally by reading the manual and would highly recommend checking the manual out to anyone interested in Caml. It has an introductory section which is enough to get you started, a detailed description of language features and the standard library.

    I would say Caml is a lot easier to get into then Scheme/Lisp or Haskell (having worked with all 3).

    Haskell and Scheme are both nicer to program in however in Haskell it is often difficult to get good performance out of the final program and at the same time maintain code that is readable (simply because you have to "help" the compiler a lot). If you don't need speed then Haskell is great although I found it fairly difficult to get into (in particular getting used to monads - not so much using existing monads as much as figuring out what they do and how they do it).

    Scheme is in some ways nicer then Haskell (extremely simple syntax, great macros, dynamically typed, great for metaprogramming) but in other ways not even nearly as nice (Haskell is a pure functional language unlike Scheme and Caml, elegant handling of side effects, type inference, pattern matching, ability to compose functions and program without variables (to some extent), lazy evaluation). My main problem with Scheme is that there aren't that many implementations that are compliant with the current standard (R5RS) and there are no decent free compilers for Scheme (especially ones that are R5RS compliant).

    Caml is easier to get into because the structure of Caml programs closer resembles structure of programs written in imperative languages. Unlike Haskell and Scheme it also comes with a great native code compiler. It's a great starting point for anyone interested in learning functional programming and once you get into it you'll never want to go back to imperative languages.

    Currently Ocaml is the only functional language implementation that can favorably compete with most imperative languages in terms of performance which makes it great for general purpose programming. MLton, a StandardML implementation, comes pretty close but it doesn't seem as mature as Caml.

    Finally both Caml and Haskell have a great foreign language interface and it's quite easy interfacing them with C.
  • Re:Intrigued? (Score:5, Informative)

    by The boojum ( 70419 ) on Tuesday November 30, 2004 @07:37PM (#10958271)
    One solution that many of these languages are now taking is to target either the .NET framework or the JVM. For example, F# [microsoft.com] and SML.NET [microsoft.com] are two different projects from Microsoft Research aimed at producing ML-like compilers targeted at .NET. The Bigloo [inria.fr] Scheme compiler now has an experimental .NET backend in addition to native code and JVM backends. There are also some Haskell compilers targetting the .NET now. If you look around, quite a few functional languages are beginning to support some combination of .NET and the JVM.

    For many languages, this solves exactly the problem that you describe. The new language instantly gets the benefit of large, useful and well tested library. The language developers can focus on the design of their language and leave the hassle of building and maintaining the supporting run-time and library to someone else. Eventually they can add a more native-feeling system library layer over it, but targeting the .NET or JVM gets them off the ground right away.

    There's a few quirks involved in shoehorning functional languages this way. As I recall, the JVM is a bit more difficult to compile functional languages to since it is really intended to run Java. .NET is a bit easier, though there are still some quirks. Many of those are known at this point, however, and there are even some libraries even to help work around them (e.g. the ILX [microsoft.com] SDK developed for F#.) I also think I recall something about the next update to MSIL addressing many of those quirks to simplify the development of functional language compilers.
  • by nietpiet ( 836036 ) on Tuesday November 30, 2004 @08:03PM (#10958541)
    but there are!
    I learned the language online, (just as i learned Java from their very good tutorial)

    they gave 2 good ones at the top.
    the Richard Jones'
    Ocaml Tutorial for people who know how to program 'normally' [merjis.com]

    There is also an update to Jason Hickey's book [metaprl.org]

    I like OCaml because it Combines the power of functional programming, like (tail-)recursion, functions as an argument, with 'normal' programming language statements.
    It doesn't force the "functional programming way" on you, like Lisp does, So, you can still use the If then, and While statements if you find them more usefull then a recursion.

    And, it is quite fast!
    both in development and in execution.
    however, i have yet to find a way to well commenting my code.
  • OCaml tutorial (Score:5, Informative)

    by Richard W.M. Jones ( 591125 ) <rich.annexia@org> on Tuesday November 30, 2004 @08:18PM (#10958643) Homepage
    Objective CAML (OCaml) is a very cool and powerful language. We use it at our company extensively, and we've released a lot of tools under open source licenses (see my signature). You can, for example, call Perl and Python libraries, and COM objects directly from OCaml, and interfacing with C is trivial.

    I've also written an OCaml tutorial for people coming from 'conventional' languages like C, Perl and Java [merjis.com].

    Rich.

  • by stdcallsign ( 558206 ) on Tuesday November 30, 2004 @08:22PM (#10958676) Homepage
    http://merjis.com/developers/ocaml_tutorial/
  • by brpr ( 826904 ) on Tuesday November 30, 2004 @08:36PM (#10958804)

    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.

    O'Caml is a more advanced language than Eiffel in most respects. It has multiple inheritance too, BTW. Features O'Caml has that Eiffel doesn't:

    * Type inference
    * Higher order functions
    * More powerful type definition (e.g. tagged unions).
    * Syntax/semantics generally much more suited to functional programming, which is pretty much impossible in Eiffel.
    * More concise.

    OK, Eiffel has design-by-contract, but that only adds additional safety, not power.

  • by Anonymous Brave Guy ( 457657 ) on Tuesday November 30, 2004 @09:54PM (#10959422)

    If you use C++ for its power and flexibility then some of the features in OCaml will make you cry, and realise how low-level C++ remains in some respects.

    I write mathematical software all day in C++, which we use for exactly those reasons (and its good portability). Still, it hurts to think how many times 5+ lines of cluttered C++ would become a single, elegant line in a decent functional language. Obviously the work I do is particularly suited to a functional style, but I've always had a background envy of people who get to use grown-up toys like this in their programming jobs.

  • RTFL (Score:4, Informative)

    by pikine ( 771084 ) on Tuesday November 30, 2004 @11:35PM (#10960010) Journal
    I'm not sure how you could refute the official objective caml license [inria.fr], 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.
  • by j1m+5n0w ( 749199 ) on Wednesday December 01, 2004 @12:11AM (#10960220) Homepage Journal
    FFTW is written in C, so I was confused what it had to do with Ocaml. According to the faq [fftw.org]:
    FFTW is written in ANSI C. Most of the code, however, was automatically generated by a program called genfft, written in the Objective Caml dialect of ML. You do not need to know ML or to have an Objective Caml compiler in order to use FFTW. genfft is provided with the FFTW sources, which means that you can play with the code generator if you want. In this case, you need a working Objective Caml system. Objective Caml is available from the Caml web page.
  • Re:Intrigued? (Score:2, Informative)

    by arjun ( 33278 ) on Wednesday December 01, 2004 @12:44AM (#10960372) Homepage
    A fair few of programming language geeks seem to be fans, but as someone posted here once before (sorry, can't remember who), functional programming has yet to find its Larry Wall.
    can you say Paul Graham [paulgraham.com]?
  • by jodonoghue ( 143006 ) on Wednesday December 01, 2004 @02:38AM (#10960906) Homepage Journal

    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.

    Conclusion

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

  • Re:Intrigued? (Score:2, Informative)

    by vague ( 107055 ) on Wednesday December 01, 2004 @05:05AM (#10961434) Homepage
    Ehrm, that's a problem of education, needing better intro texts, not of the language. Here's the truth: functional programming is no harder to imperative programming. It only appears that way because most of the current educational material isn't written by people who understand the needs of non-programmers. The bracketing is only a problem for those who are used to different syntaxes really.
  • by sangdrax ( 132295 ) on Wednesday December 01, 2004 @05:34AM (#10961524)
    Its not that simple. C++ doesn't provide functional programming constructs; OCaml does and encourages its use. Functional programming can cost much more resources than OO programming.

    To compile functional code that looks pretty, the result is often resource wasteful:

    - Memory is copied at every turn (in functional constructs, variables cannot be changed),

    - About all small functions use recursive calls (no, tail-recursion doesn't solve most of them; often the result of the recursion has to be modified before returned),

    - Generic functions cannot be optimised well (C++ compiles a specific version at instantiation with a template).

    To name a few. If you want raw execution speed in OCaml, use the procedural constructs. The computer is built to run code like that.
  • Re:Intrigued? (Score:3, Informative)

    by Richard W.M. Jones ( 591125 ) <rich.annexia@org> on Wednesday December 01, 2004 @05:41AM (#10961543) Homepage

    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, [...]

    This may have been true 5 years ago, but today you can call Perl 5 libraries [merjis.com] and Python libraries [sourceforge.net] directly from OCaml.

    Rich.

HELP!!!! I'm being held prisoner in /usr/games/lib!

Working...