Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'd like to like ocaml but its not clear to me why I would choose it above anything else to write an application. I have the sense vaguely it might be a good thing. A little reading and examination of some example source hasn't thrown much light.

What's it good for? Why should I use it? Why is it a better choice than language X or Y?



The overview of Real World OCaml might help answer that:

https://realworldocaml.org/v1/en/html/prologue.html#why-ocam...

"Among this worthy set of languages, OCaml stands apart because it manages to provide a great deal of power while remaining highly pragmatic. The compiler has a straightforward compilation strategy that produces performant code without requiring heavy optimization and without the complexities of dynamic just-in-time (JIT) compilation. This, along with OCaml's strict evaluation model, makes runtime behavior easy to predict. The garbage collector is incremental, letting you avoid large garbage collection (GC)-related pauses, and precise, meaning it will collect all unreferenced data (unlike many reference-counting collectors), and the runtime is simple and highly portable."


The brief look I had at some of the source examples seemed a little arcane. To be fair that's probably same as any unfamiliar language I suppose.


It's really fast, has minimal boiler plate and supports functional programming without any of the "orthodoxy" of Haskell. That is, you can write a recursive function but also write a for loop.

Imagine something that can compete with C and C++, but doesn't require all of the low-level reinvention and memory management. It's like a high-level language for smart people that doesn't feel entirely impractical. It has some things that people bitch about (like having to use +. to add two floats and + to add two ints), which don't really bother me that much.

If it were more popular and had better libraries/platform support (unless that's changed drastically in the past year or so), it would be a serious contender for general development. Being completely honest, I think Jane Street is probably the biggest organization pulling OCaml, and from a navel-gazing standpoint you can either view that as good or bad.

Use it because you learned it and thought it didn't suck, I guess?

EDIT: changed some phrasing


> "... unless that's changed drastically in the past year or so ..."

Actually a lot has happened in the last year or so. If you're not aware of it, you could start by looking over the end-of-year post from OCaml Labs [1]. I'm aware that it's difficult to keep a central overview of all the progress but there is a lot of work being done, in many ways, to improve the ecosystem.

[1] http://www.cl.cam.ac.uk/projects/ocamllabs/news/#Dec%202013


Whoa, that's cool. I had no idea people were still working on it at that level. The last thing I saw was a version of OPAM that didn't seem to work that well...I'll have to go look around.


I think we're pretty clearly the most intense user (most code, most developers using it), but not technically the biggest company using it. Bloomberg and Facebook are examples of bigger companies using it in serious ways.


Yep, that's what I was trying to convey.

Thanks for your work.


We use it in our backend to tie everything together. It serves an http/json api to our client apps (Web/JavaScript, Android/Java; iOS/Objective-C coming soon). We're handling the same data types in JavaScript, Java and OCaml.

What is clear is that we spend a lot of time fixing type errors in JavaScript due to the lack of basic type checking. Java does not have this problem and for Android programming it is a breeze since really the mobile app is just a GUI which doesn't have to do anything clever with the data.

Now the backend is in charge of serving correct data to the client apps. I could explain that OCaml is fast and lets us implement any CPU-intensive algorithm without having to switch to C, but the truth is most of our code is not much about algorithms but very much about data modeling and data management. Anything we store needs to be stored correctly if we don't want to accumulate broken data resulting in bugs that are costly to fix. Untyped languages such as JavaScript let you store anything without checking their conformance to a type definition, this is awful. Java for example would be perfectly acceptable if it wasn't so verbose. We want to write JSON-like records and arrays like in JSON or JavaScript. OCaml provides this, Java doesn't.

Now, we don't want half of our code to consist in annotating each variable with a type. The compiler should infer that 123 is an int. How hard is that? You tell me. JavaScript doesn't check anything. Java or C++ force you to declare that 123 is an int. How clever is that? I don't know. OCaml, Haskell just figure out that 123 is an int. That's called type inference. That makes code readable like JavaScript or Python, with the safety of Java and the performance of C++.


It's not clear to me why you'd choose OCaml over Haskell. I understand that OCaml isn't lazily evaluated like Haskell and has a simpler to understand compiler which gives a better understanding how the code will perform at runtime. But why as someone new why would I choose OCaml over Haskell?

From my perspective it seems like there is more activity and research going on in Haskell.


> I understand that OCaml isn't lazily evaluated like Haskell and has a simpler to understand compiler which gives a better understanding how the code will perform at runtime. But why as someone new why would I choose OCaml over Haskell?

Isn't that enough to choose OCaml over Haskell?


Why would that be enough on its own? If that alone is sufficient, he should choose C over both OCaml and Haskell.


Haskell comes with a very big community, and a lot of ways to start with the languages. I think about the http://learnyouahaskell.com/ and others.

Real World OCaml is that, without totally being it. The authors wrote it with the idea in mind that only people with a good background about functionnal world can read it.

I'd add that lazyness can be a good thing and that the type-system of Haskell is better than the OCaml one.


As I'm aware, finance industry now prefers F#. Regarding Haskell - one of its biggest user (Standard Chartered I think) uses in-house dialect of it, miu, which is strict. Basically, it just syntactically resembles Haskell... i.e. you can't just use some random Haskell library with it.


Where did you hear about this? Googling around for "miu", "miu haskell", "miu haskell standard chartered", "miu haskell standard chartered strict", etc hasn't given me anything.


It's "mu" not "miu". I think they gave a talk on it at CUFP one year.


Pure Haskell is slow, that is why.


[citation needed]


Are you just using OCaml as an altjs then? And/or on the backend?

Any reason to try OCaml for Android development? Looked at Ocaml-Java?


For our web app we've been sticking with JavaScript so far. It's a conservative choice with a lot of problems due primarily to the absence of typing. The absence of typechecking is a problem for our moderately complex app (> 10K lines).

Alternatives that we've been considering include js_of_ocaml and TypeScript.


For the kind of Android app we're developing we wanted a native look-and-feel. That means using the Android SDK, and I don't know how going through OCaml would make that any easier.


Have a look at Thomas Leonards blog, where he chooses Ocaml to replace Python over many others for his 0install project.

http://roscidus.com/blog/blog/archives/

It has been previously discussed on HN and Reddit.


Languages in the ML family are getting into the industry via data modeling.

From what I can understand in the SkillsThatMatter sessions, the finance and insurance sector in some European countries are big users.

The applications aren't full ML stacks, just the algorithms are done with them, with the UIs using a more traditional one.

Might not seem much, but it already a foot in the door.


apart from the more objective criteria, it's simply a very pleasant language to use. i usually evaluate new application programming languages by what they offer me that ocaml does not.


Algebraic data types and pattern matching are bliss. It's almost a cliche, but you don't know what you're missing without them and once you know them you'll wish every other language had them.


I suspect the main reason why Jane Street uses OCaml is Yaron Minsky.




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

Search: