Hacker News new | past | comments | ask | show | jobs | submit login
OCaml as a scripting language (janestreet.com)
26 points by 10ren on July 23, 2010 | hide | past | favorite | 12 comments



I'm sure Jane Street knows their stuff when it comes to OCaml... but this is fluff. Some examples would be nice.


It seems like OCaml is mostly dead and Jane Street is the only place it is still used.


People from Mozilla, including Brendan Eich, creator of JavaScript, are working on a new language called Rust. The compiler is written in OCaml.

http://lambda-the-ultimate.org/node/4009


The increased availability of libraries for Haskell and Erlang's suitability for distributed applications kinda stole OCamls thunder.

It is quite nice for Unix development, due to some concessions to "impure" practices. I use the Unison file synchronization tool at work, and used to run mldonkey in my wild file-sharing days… That area is mostly dominated by C tools, as scripting languages are either too slow / memory intensive or carry a lot of baggage with their runtimes and libraries. And for a long time, OCaml was one of the few (open source) compilers at all that could produce fast and small (i.e. no full images) code for the free Unix variants.

But yeah, that article would have been better with some simple examples. Hope they're going to share one of these toplevels.


For sake of argument, how does the environment/type system determine if something is a "real program" or "scalable" ?


It's all about two things:

1. Eliminating runtime errors(type mismatches, segmentation faults, and null pointer exceptions are a few problems that have been hammered on a lot and in some languages eliminated entirely). 2. Being able to manage a large project effectively. Things like build systems, code editors, debuggers, and perhaps most of all, access to libraries/hardware for the problem domain.

Newer general-purpose languages(under ~5-10 years) tend to offer compelling features in the first case, but almost nothing in the second, which makes a commercial project in them an expensive prospect.


If I was going to delve into another language why would it be OCaml over Haskell or Scheme?


There are some practical reasons, but if you haven't learned any of them, it's hard to recommend Caml. Both Haskell and Scheme (and I'd add Prolog) offer some interesting ways of reasoning about programs, even if you don't end up working with them in the end.

As for usage scenarios: Compared to Scheme, you might like the syntax more, it's statically typed and has a very fast compiler that doesn't even need to use C as an intermediate language. Haskell is much more pure regarding its functional nature and thus its way of interacting with a state-ful world can seem a bit intimidating. If you don't have a lot of math under your belt, Caml's way of interpreting code is a bit easier to mentally model.

I've always thought of ML as the C to Haskell/Miranda's Pascal, for better or worse…

Library-wise, Caml has a very good foundation for writing Unix software. Haskell has made major steps in catching up, Scheme is still a bit balkanized (going from your teaching language to the Chicken/Gambit/PLT infrastructure is not much easier thank taking up Common Lisp).

I'm still surprised at how far Haskell has come in recent years in getting more libraries. It used to be slightly below Common Lisp in that regard, if my memory serves me. Now Hackage is huge. GHC always was a pretty good compiler, so nothing major about the language or its implementation changed. I also know of no big poster boy use cases, compared to e.g. Erlang. Linux hackers impressed by xmonad?


Scheme has a Lispy syntax (good or bad depending on where you're standing, but probably not neutral) and doesn't have static type inference, which is the whole point of the article. Haskell is just enormously complex for anyone who doesn't have a very strong background in maths and category theory. Seriously, it's an amazingly cool language, but unless you can look at ST and not feel a little confused at first, you won't be able to shake the feeling that Haskell is smarter than you are.

OCaml is a reasonable middle path. It has a lot in common with Haskell (H-M typing, ML syntax, pattern matching) and is largely pure, but doesn't absolutely force purity on a language level the same way Haskell does. Strictness is the default, with laziness as an option, so there are no surprising space leaks. IO is performed with IO functions, not with some bizarre monad that is the description of an action that would be performed.


Personally I like Haskell. As for reasons to choose it over Haskell, I find it to be a bit simpler and easier to get things done. Mutable state takes less work. For places where you might drop down to C for bit twiddly speed it is easier to replace C with OCaml than Haskell. You can still do lazy in OCaml though you have to choose it. It is a part of the standard library. Being an eager language it's evaluation model is easier to understand.

OCaml vs Scheme is harder for me to answer I haven't used Scheme that much. Static typing if you like that sort of thing.


I'll pick on Haskell since that's the one I've used and like. Sometimes you get the feeling that people go overboard with the type system, I've passed over potentially better libraries for ones that are a bit more redneck friendly. The next annoyance is operator explosion. Ran into one that was a constructor in Happs. Hoogle and Google were useless. Eventually grep won the day. The final issue I have is that sometimes the type in the standard libraries aren't quite what you want. Fortunately they seem to be fixing this.


As they use OCaml a lot, they are determined to used for everything and will overcome any difficulty, so they will succeed. Scripting is not a high barrier for such determined persons.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: