Live data from Hacker News

Unix system programming in OCaml

ocamlunix.forge.ocamlcore.org

11–16 of 16 posts

Re: Unix system programming in OCaml

#11
post #7
post #4

Earlier quoted context omitted.

And the community isn't as vibrant as the communities of other functional languages such as Clojure or Haskell

...good luck having a trader with very basic coding knowledge "review" Haskell or Clojure code (the process JS is "famous" for) - even if they understand the value of it and are willing to learn it, it will always be a huge mental effort handling monads or reading code "inside our" lisp-style. And coders will not resist doing "smart stuff" in languages like Clojure or Haskell, which will make everything worse. Otoh,…

Without firsthand knowledge of the Jane Street corporate environment it is naive of me to think that allowing engineering to pick the tools which best let them get their work done need not be incompatible with the requirements of non-expert review of the source code.

I would think that if the company culture is one where it is expected that your code is going to be reviewed by domain experts, but not necessarily language experts, there would be a strong emphasis placed on producing source code which would convey its meaning without a detailed knowledge of the language spec and runtime system.

Re: Unix system programming in OCaml

#12
post #3

Language-wise, it is a really nice and interesting, indeed. But two things keep me away from OCaml, both reported by the same company (Jane Street), which apparently uses OCaml in production: 1. Standard library was so weak that they had to come up with in-house replacement (which is now open sourced). 2. No true parallelism due to runtime limitations (single runtime lock) - http://queue.acm.org/detail.cfm?id=2038036

3. The compiler's error messages lack useful detail (e.g. "syntax error" and a line number!) 4. Stack traces are as likely to be wrong as right 5. Too much boilerplate exception handling (e.g Not_found) 6. Clunky type polymorphism (e.g. Set)

Claims 3 and 6 lack a true understanding of Ocaml. The compiler's error messages are exceptionally good in most cases.

Syntax errors without detail are a product of the parsing technology: its a minor irritant and worst.

The most difficult problem (IMHO) comes from type inference when a type inferred from context is not the one intended, but a conflict is not discovered until code with the intended typing is found: the error reflects the second location which is confusing because there is no error at that point. Of course this doesn't occur if you actually provide type annotations, so it is merely a cost of being able to omit them.

The excess exception handling is a reasonable comment, however it is easy to wrap the exception throwing code in a variant to enforce local error checking, and in any case this style is a property of the library, not the core language.

The type polymorphism in Ocaml is anything but clunky: for basic stuff you don't even need any type annotations. The thing is that Set us NOT type polymorphism. Its module polymorphic, and that requires explicit binding of an instance. There is a simple enough reason: module functors take non-type arguments, particularly function closures, which are values, which do not have unique signatures, so implicit instantiation is not possible.

Ocaml does have some other serious disadvantages. One is that because of the way the optimiser uses information from compiles on which it depends, there are annoying constraints on build order. In addition, recursion cannot span compilation boundaries which is pretty lame for a functional programming language: even C has no problem with that.

Finally, the political situation is probably the biggest problem. The development team is excellent but limited and their focus is on the type system, rather than libraries. Because the community is modest compared to say C++, many attempts to make extended libraries have failed to gain acceptance, because no one wants to depend on an unresourced third party library and the core INRIA team doesn't have the resources or interest to extend the standard distribution.

Despite these difficulties .. I would never want to go back to writing C++ (OMG .. the pain!). As a language .. Ocaml is light years ahead.

Re: Unix system programming in OCaml

#13
post #3

Language-wise, it is a really nice and interesting, indeed. But two things keep me away from OCaml, both reported by the same company (Jane Street), which apparently uses OCaml in production: 1. Standard library was so weak that they had to come up with in-house replacement (which is now open sourced). 2. No true parallelism due to runtime limitations (single runtime lock) - http://queue.acm.org/detail.cfm?id=2038036

I end up using F# more, as it is way easier to introduce in Windows based environments than OCaml is.

Re: Unix system programming in OCaml

#14
post #3

Language-wise, it is a really nice and interesting, indeed. But two things keep me away from OCaml, both reported by the same company (Jane Street), which apparently uses OCaml in production: 1. Standard library was so weak that they had to come up with in-house replacement (which is now open sourced). 2. No true parallelism due to runtime limitations (single runtime lock) - http://queue.acm.org/detail.cfm?id=2038036

> 2. No true parallelism due to runtime limitations (single runtime lock)

I've thought about this, and it's not a big deal in the multicore/SMP sense. For I/O concurrency, there is LWT or Async. It does fall short for "small-scale" parallelism though, eg map-reduce over an array, multiplying big-but-not-huge matrices, etc. At least OCaml doesn't pretend to support threading, unlike most other GIL-bound languages.

For high-concurrency or large parallel problems, multiple processes are a better option since that naturally scales beyond a single machine. OCaml's memory footprint is easily an order of magnitude smaller than eg, Ruby's, so I could run 10x the number of workers using the same resources. And then they'd complete tasks faster, thanks to excellent single-thread performance.

In some sense, OCaml indirectly enables the best of the Unix tool tradition. The maintainers haven't tried to throw the kitchen sink at the language, which practically encourages composable designs where distributed/parallel systems are concerned.

Re: Unix system programming in OCaml

#15
post #12

Earlier quoted context omitted.

3. The compiler's error messages lack useful detail (e.g. "syntax error" and a line number!) 4. Stack traces are as likely to be wrong as right 5. Too much boilerplate exception handling (e.g Not_found) 6. Clunky type polymorphism (e.g. Set)

Claims 3 and 6 lack a true understanding of Ocaml. The compiler's error messages are exceptionally good in most cases. Syntax errors without detail are a product of the parsing technology: its a minor irritant and worst. The most difficult problem (IMHO) comes from type inference when a type inferred from context is not the one intended, but a conflict is not discovered until code with the intended typing is found: t…

> Syntax errors without detail are a product of the parsing technology: its a minor irritant and worst.

You may think so, but it infuriates me many times a day. This is the most basic thing which a compiler should be getting right, and yet they fail.

I agree with you on type inference errors, but my solution is to annotate function parameters, which avoids the most confusing problems.

I don't want to wrap my error handling code, or work around it with other libraries, I just want something usable out of the box. Languages need to be evaluated holistically, and the design of the standard library is a critical part of that, look at the C++ STL.

Yes, I meant module polymorphism. I much prefer the way that F# deals with Sets, Maps, etc.

I think Ocaml has had a good run, but it's starting to look dated, F# has really innovated, it's just a shame that it's tied to .NET.

Re: Unix system programming in OCaml

#16
post #3

Language-wise, it is a really nice and interesting, indeed. But two things keep me away from OCaml, both reported by the same company (Jane Street), which apparently uses OCaml in production: 1. Standard library was so weak that they had to come up with in-house replacement (which is now open sourced). 2. No true parallelism due to runtime limitations (single runtime lock) - http://queue.acm.org/detail.cfm?id=2038036

> 2. No true parallelism due to runtime limitations (single runtime lock) I've thought about this, and it's not a big deal in the multicore/SMP sense. For I/O concurrency, there is LWT or Async. It does fall short for "small-scale" parallelism though, eg map-reduce over an array, multiplying big-but-not-huge matrices, etc. At least OCaml doesn't pretend to support threading, unlike most other GIL-bound languages. For…

> At least OCaml doesn't pretend to support threading, unlike most other GIL-bound languages.

OCaml does support threading, you don't need LWT of Async for I/O concurrency.

http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual039.ht...

Post reply on HN