Slashdot Mirror


Developing Applications With Objective Caml

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.

54 of 243 comments (clear)

  1. MLDonkey by Megaslow · · Score: 3, Informative

    Possibly the most widely used app written in Objective Caml -- MLDonkey

    1. Re:MLDonkey by bcrowell · · Score: 2, Informative

      Also unison, which is a great app.

    2. Re:MLDonkey by Anonymous Coward · · Score: 2, Funny

      You're obviously kidding, the true fault clearly lies in the x86 instruction set and assemblers. If they had only stopped to think about how end users would take those innocent MOV's and POP's and pervert them into Peer2Peer thought-stealing technology. How many billions in "lost" content revenue would have been saved? What about the children?

  2. Muchly needed by Tibor+the+Hun · · Score: 5, Funny

    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.
  3. Intrigued? by hobuddy · · Score: 5, Insightful

    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
    1. Re:Intrigued? by Anonymous+Brave+Guy · · Score: 5, Interesting

      I totally agree with your comments about the need for a standard library. But, as you observe yourself, such things can be developed by the community: CPAN for Perl, CTAN for TeX, and Boost for C++ are all very high quality libraries that are pretty much entirely community-developed.

      I think the most obvious missing thing is a figurehead for functional programming. 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. I'd like to think that the first time someone steps up and takes on that role, that will get the geeks going, and the snowball will start to form. All we need is someone qualified who wants to put in the effort, but of course there are going to be very few such people around in a relatively small corner of the programming world -- catch 22, indeed.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Intrigued? by Anonymous Coward · · Score: 5, Informative

      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.

    3. Re:Intrigued? by srussell · · Score: 4, Informative
      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 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

      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

    4. Re:Intrigued? by Coryoth · · Score: 4, Interesting

      I totally agree with your comments about the need for a standard library. But, as you observe yourself, such things can be developed by the community: CPAN for Perl...

      On that front, it will be interesting to see what will happen in Parrot successfully manages its dream of uniting (amongst others) Perl, Python and Ruby - allowing a module from one language to be used in another. Surely that confluence of communities could build a very formidable library indeed...

      Jedidiah.

    5. Re:Intrigued? by upsidedown_duck · · Score: 2, Interesting

      The same limitation applies to Lisp, Scheme, Haskell, Erlang, etc.

      (Common) Lisp lacks only a non-proprietary and useful GUI toolkit. Otherwise it has just about everything. The fact that POSIX interoperability doesn't appear standardized is annoying, but the most annoying thing is that the good Lisp environments cost $$$$. I envy Lisp developers from a distance have never had the balls to really become one myself. It does take balls, too, to say to a group of Java-nerds or C++-nerds that something can be done better, faster, and with fewer problems.

      --
      -- "Makes Little Debbie look like a pile of puke!" - Moe Szyslak
    6. Re:Intrigued? by The+boojum · · Score: 4, Informative

      One solution that many of these languages are now taking is to target either the .NET framework or the JVM. For example, F# and SML.NET are two different projects from Microsoft Research aimed at producing ML-like compilers targeted at .NET. The Bigloo 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 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.

    7. Re:Intrigued? by hobuddy · · Score: 2, Insightful

      The problem with .NET or Java as a solution to the library problem is that you end up using your functional language:

      1) On a proprietary runtime. In the case of .NET, it's also a platform-specific runtime. Don't even bother mentioning Mono; the Microsoft Corporation that exists in the universe I inhabit will never allow Mono to grow into anything more than a token antitrust smoke screen, a perpetually not-quite-ready, not-quite-compatible runner-up. If you expect Microsoft to behave differently, you must not be referring to the corporation that's been systematically raping its competitors by whatever means necessary for the last two decades. The safest elements of .NET--those that have been submitted to ECMA--exclude almost all useful libraries.

      2) With libraries that were designed for consumption by object-oriented client languages, which robs the would-be functional programmer of much of the value of the functional way. The programming experience degenerates into a sad parody of functional programming that really amounts to object-oriented programming through a functional condom. To paraphrase the famous quote about condoms, "Functional programming with object-oriented libraries is armor against productivity, gossamer against library scarcity."

      3) On a runtime that performs 3-10 times worse than a runtime designed for the langauge in question.

      --
      Erlang.org: wow
    8. Re:Intrigued? by srussell · · Score: 2, Funny
      No, I think the preferred way is to use real bindings, although I haven't done a speed test to see if there's any real advantage to a true binding. I like Ruby/DL because I've been able to write a cross-platform binding for Matlab with it -- something I was unsuccessful at doing with the standard method. As you suspect, not requiring a C compiler is a huge advantage, especially on Windows.

      --- SER

    9. Re:Intrigued? by matthewknox · · Score: 2, Interesting

      actually, this is not a significant issue in lisp anymore. Lisp developers can access any java libraries from jfli . This is a pretty amazing hack, and means that lisp probably has better library support than any other language at the moment, given that lisp calls to C with ease and has pretty significant native libraries, too. It almost begs the question: what excuse are the parenphobes going to use now?

    10. Re:Intrigued? by arjun · · Score: 2, Informative

      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 ?

    11. Re:Intrigued? by edp927 · · Score: 2, Funny

      The real problem with OCaml (and modern functional programming in general) is that its too frnech. perhaps if it were called Freedom Programming....

    12. Re:Intrigued? by vague · · Score: 2, Informative

      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.

      --

      -
      Listen. Strange women lying in ponds distributing swords is no basis for a system of government.

    13. Re:Intrigued? by Richard+W.M.+Jones · · Score: 2, Informative

      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 and Python libraries directly from OCaml.

      Rich.

  4. I tried learning OCaml by Coryoth · · Score: 3, Insightful

    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.

    1. Re:I tried learning OCaml by drafalski · · Score: 3, Informative

      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 gives a good general background including OCaml references. The homework page 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.

    2. Re:I tried learning OCaml by Anonymous Coward · · Score: 2, Informative

      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.

  5. My first Caml script... by Anonymous Coward · · Score: 4, Funny

    _
    .--' |
    /___^ | .--.
    ) | / \
    / | /` '.
    | '-' / \
    \ | |\
    \ / \ /\|
    \ /'----`\ /
    ||| \\ |
    ((| ((|
    ||| |||
    //_( //_(

    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.

  6. Chapter 8: Toes by apachetoolbox · · Score: 4, Funny


    :D

  7. Careful about speed comparisons by Junks+Jerzey · · Score: 5, Interesting

    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.

    1. Re:Careful about speed comparisons by Svartalf · · Score: 3, Insightful

      Considering that the C++ code would have nasty solutions for peak speed- prettier, straightforward solutions for C++ tend to be 2-4x slower than the optimal solutions for C++. The same could be said for C code as well.

      --
      I am not merely a "consumer" or a "taxpayer". I am a Citizen of the State of Texas
    2. Re:Careful about speed comparisons by KoporShow · · Score: 3, Insightful

      The performance difference between C and OCaml depends heavily on the application. I have written a relatively small application in OCaml (an interpreter for the programming language Joy) and the optimized OCaml version was faster than its C counterpart. (The C version, not programmed by myself, is about 6x larger and still slower) There are examples where OCaml is significantly slower, but I think, that you would rarely see a 2X slowdown when programming carefully. On the other hand the development time can be significantly reduced: programming in OCaml is normally about 2-5 times faster than in C++ if one takes the reduced time for debugging into account. And this is true for ma altough I have more than 8 years (and over 100 KLOC) C++ experience while less than one year OCaml experience. One can also add that the object system of OCaml is much more powerful than that of C++. It allows for much more genericness while having a thourough type-safety. You can not achieve the same genericness in C++, since you can add everywhere explicit type delaration (resulting in long and complicated template names) where OCaml can deduce the type information automatically. This makes code-refactorization much more easy. It is not true that OCaml needs a different type of thinking than a procedural or object-oriented language. OCaml has full support for "traditional" programming style and in fact most OCaml programs are written that way. Haskell and Clean are more elegant, but they really require that the programmer uses a purely functional programming style without mutable states.

    3. Re:Careful about speed comparisons by Junks+Jerzey · · Score: 3, Interesting

      But isn't this in general true of all languages? I mean, to write C code to the highest potential, you have to occasionally drop down and inline some cryptic ASM to punch up those few routines that are slow and commonly called.

      Well, not quite. In C you pay as you go. You essentially have a direct mapping to common hardware. You can go faster, yes, but the improvement generally isn't worth it unless you're targeting specific weirdness like MMX or SSE2.

      OCaml has some significant overhead that comes from the language definition. There's garbage collection, which while fast is certainly not free. Floating point values in mixed-type tuples are heap allocated (that is, the floating point values--doubles, actually--are separate heap objects). There's the classic issue with functional languages that the simple and easy way to build a list either involves stack space for each element or a full reversal of the list (not in place) at the end.

      I fully agree with you that readability is worth a hit in performance. I use interpreted languages all the time, and compiled OCaml is certainly much faster than them. But OCaml advocates need to be careful about claiming their language is as fast as C/C++, because it generally isn't true. It's only true if you drop the nice features and write grungy C-style code, and then only in certain situations. This does not mean it is a bad language, however.

    4. Re:Careful about speed comparisons by sangdrax · · Score: 2, Informative

      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.

  8. Full Support? by engywook · · Score: 3, Informative

    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"
  9. Attack a niche by DavidNWelton · · Score: 2, Insightful

    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.

  10. FFTW by geneing · · Score: 2, Funny

    I think FFTW would be the most famous and useful if not the most popular.

    1. Re:FFTW by sketerpot · · Score: 2, Funny

      For those who haven't heard of it, FFTW stands for Fastest Fourier Transform in the West, and it's a library for computing some discrete Fourier transforms really quickly.

  11. Huh. by rackhamh · · Score: 2, Interesting

    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.

  12. Dear CowboyNeal by zoloto · · Score: 3, Funny

    Does this count the same as anyone from GNAA?

    Or because it's CAML, will it be allowed? Please tell me what to flame!

  13. In related news, by Anonymous Coward · · Score: 2, Funny

    In Korea, only old people use scripted languages.

  14. No good tutorial about ocaml... by zymano · · Score: 3, Insightful

    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.

    1. Re:No good tutorial about ocaml... by nietpiet · · Score: 3, Informative

      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'

      There is also an update to Jason Hickey's book

      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.

    2. Re:No good tutorial about ocaml... by rsidd · · Score: 2, Interesting

      There's a bunch of good tutorials here. I learned everything I know about ocaml from there, in particular from Jason Hickey's, Richard Jones' and the OCaml manual. I spent a week learning that stuff and playing with it, and another week writing from scratch a rather non-trivial program that would have easily taken two months in C. I found ocaml astounding: nearly as fast as C, as compact and elegant as python (arguably more so, in fact).

  15. Re:I'd consider OCAML by KoporShow · · Score: 2, Interesting

    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.

  16. First o'caml script by sik0fewl · · Score: 3, Funny

    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
  17. Pascal comment by Trillan · · Score: 2, Insightful

    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.

  18. Things I want to know about a new language: by Pacifix · · Score: 2, Interesting

    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.

    1. Re:Things I want to know about a new language: by ElHorrendo · · Score: 3, Funny
      There are many reasons why OCaml comes out on top in language comparisons. Go to the The Computer Language Shootout Benchmarks and compare them yourself. To name a few:
      • Interactive interpreter and fast native compiler.
      • Parametric polymorphism
      • Pattern matching
      • Functors
      • Highly efficient garbage collection
      • Closures (which I find to be more powerful than Objects)
      • Functions as first class values
      • Derived types - Ocaml is efficient, static and strongly typed, but you can write without explicit typing.
      • Time travel debugger (step forward or backward)
      • Very fast and efficient code.
      • Minimal memory consumption.
      See the Wikipedia for a brief overview.
    2. Re:Things I want to know about a new language: by Anonymous+Brave+Guy · · Score: 2, Informative

      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.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  19. OCaml tutorial by Richard+W.M.+Jones · · Score: 4, Informative
    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.

    Rich.

  20. Mercury by G.+Waters · · Score: 2

    Here is a beautiful derivative of prolog in desparate need of an o'reilly treatment.

  21. Re:Man, I still don't 'get' functional programming by stdcallsign · · Score: 2, Informative

    http://merjis.com/developers/ocaml_tutorial/

  22. Re:Eiffel is all this and more... by brpr · · Score: 2, Informative

    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.

    --
    Freedom is not increased by mere diminuation of government. Anarchy is freedom for the strong and slavery for the weak.
  23. Re:manual by 808140 · · Score: 2, Interesting

    Lots of CS majors don't cope well with functional programming paradigms. In the old days (and at many tier 1 CS universities) Lisp or Scheme are still taught as introductory languages, which helps some.

    Functional languages are very intuitive to math majors, and people who study abstract computer science (which is essentially discrete math). Concepts like currying, recursion, and the like make a lot of sense if you're used to the way mathematicians think.

    I don't know Ocaml, but I do program in Haskell. I remember looking at the language as a freshman and finding it very confusing. By the time I'd taken graduate level math classes though, and was comfortable with functors and morphisms, lambda calculus and Haskell were not only a piece of cake, but incredibly intuitive.

    Note that this way of thinking is (at least in my opinion) no more "intuitive" than procedural programming paradigms. It just depends on your background. I had some classmates that never groked programming until they were introduced to ML or Prolog.

  24. RTFL by pikine · · Score: 3, Informative

    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.
  25. Further clarification by j1m+5n0w · · Score: 3, Informative
    FFTW is written in C, so I was confused what it had to do with Ocaml. According to the faq:
    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.
  26. An alternate view of the book by jodonoghue · · Score: 2, Informative

    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.

  27. Re:great language, but not quite general purpose by geg81 · · Score: 5, Insightful

    1) What do you consider "about as efficiently?" A ten-second search turns up an FFT benchmark written by Xavier Leroy; he reports that it runs about 2/3 as fast as C code.

    That code doesn't use a complex datatype--it uses real arrays and writes out the complex number operations. The FFT example was not to get an FFT, it was to illustrate a point about what operations a language can and cannot support.

    2) What the hell kind of "modern general-purpose application" needs to compute FFTs quickly? That's a highly specialized application.

    FFT itself is needed by lots of applications: financial software, image processing software, speech recognition software, speech synthesis software, etc. But it isn't about FFT in particular or complex numbers in particular: you encounter analogous problems with datatypes appearing in graphics, reliable numerical computing, graph algorithms, language processing, statistics, and lots of other areas.

    3) If certain algorithms cannot be computed quickly in OCaml, just write them in C. Bindings to C functions are trivial to write. You want to do FFTs? It's already been done.

    You just don't get it, do you? Numerical, semi-numerical, statistical, scientific, graphics, and visualization code is moving into applications and the people who are writing want better tools for writing it than using C or even C++. We are f*cking tired of being told by ivory-tower compiler writers that we should just write our code in C just so that they don't have to get their hands dirty. I have "just linked in" C code for 20 years: it's a lot of work, it's difficult to package, and it erases all the runtime safety that writing in OCAML should give you. It's time that language designers with aspirations for designing general purpose languages get a clue.

    Languages like OCAML and Java are defective as general purpose languages because they don't support efficient data abstraction for numerical types. The fact that their designers just don't get that fact is a testament to the ignorance of their designers. It's also what people really mean when they say that those kinds of languages are "just not efficient as C/C++": it means that in C/C++, you can get whatever code you write to run fast, while in OCAML or Java, there are always problems where you have to drop down to C.

  28. Re:great language, but not quite general purpose by geg81 · · Score: 2, Interesting

    I'm not sure I agree with the conclusion that OCaml (like Java) is defective due to deficiencies in handling of numeric types

    Don't get me wrong: I think OCAML is a great language for specific application domains (theorem provers, compiler writing, etc.), and Java has become a decent language for traditional server-side applications. But in order to become general purpose languages, languages that people can use instead of C/C++ without reservation, I think they must get better numerical support.

    Better numerical support does not mean that those languages have to get implementations that can beat optimized Fortran. It also does not just mean that it is possible, in principle, to write fast numeric code (you can write fast numeric code in Java and OCAML if you really have to--it just is a lot of work). It means that people can write decently clean, maintainable numerical code without having to make much of an effort.

    The thing that is frustrating is that language designers keep underestimating the importance of good support for that kind of programming, and one promising language after another dies because of of that misjudgement.

    In the case of Java, people now have an alternative: C# is basically Java with those missing pieces added. There are lots of political issues surrounding the two languages, but if it just came down to technology, it would be a no brainer to figure out which one would win in the market. And I think functional programming languages won't make it big time until one of them adds analogous functionality.