News for hackers. Stuff that matters.
Re:Why We Use OCaml by seliopou on Wednesday July 16, 2014 @03:48PM (#8044093)
I've used Haskell to build JavaScript tools and analyses[0], among other things[1], and have been using OCaml for the past nine months to develop a software-defined networking controller called frenetic[2]. Off the top of my head, here are a few areas where OCaml has an edge on Haskell:

1. The module system. OCaml's module system is a language in and of itself. It not only allows you to define modules that export certain identifiers and types, it also allows you to write functors, which are essentially functions in the module language that can take a module as an argument and produce a new module as a result. This is a great way of reusing code in a project as well as defining external APIs in a general but natural way. OCaml's module system the closest I've seen to realizing the dream of building software by taking some modules from here or there and composing them together.

2. Mutation. Unlike Haskell, OCaml allows mutation. Specifically, OCaml allows value mutation in certain contexts, while both Haskell and OCaml do not allow variable mutation. What this means is that in both languages, if you have an identifier, you cannot change the value that the identifier points to; you can only shadow the identifier with a new binding. But in OCaml, you can declare certain fields of your types to be mutable. You can also wrap values in a "box" which allows you get the same feel that you would out of variable mutation. While in general it's a good idea to limit your use of mutation, sometimes you know it's ok and you just want to do it. OCaml lets you do that, but it requires you to be explicit about it rather than just letting you do it willy-nilly.

3. gdb-able. If you know how to use gdb (and even valgrind I believe), you can use it to debug your OCaml programs. If you try and use these tools with Haskell, you will get nothing but nonsense until you learn how to read the matrix. This fact by itself for some people will make OCaml a candidate for systems programming over Haskell.

4. Subtyping. Certain features of OCaml's type system allow you to do subtyping, complete with type variable annotations to indicate covariance or contravariance. This is a feature that Haskell's type system does not have, so in a sense this is a strength of OCaml. However in my experience, this feature of the type system is hard to use and reason about, and I've seen little (maybe no?) code in the wild that takes advantage of it, with the exception of some simple inference the type system can do in this respect related to polymorphic variants[3].

All that being said, Haskell's still my hobby language of choice. But for building real systems, I'm warming to idea of OCaml as a viable candidate language.

[0]: http://www.cs.brown.edu/research/plt/dl/adsafety/v1/

[1]: https://github.com/seliopou/typo

[2]: https://github.com/frenetic-lang/frenetic

[3]: https://realworldocaml.org/v1/en/html/variants.html#polymorp...

Re:Why We Use OCaml by spott on Wednesday July 16, 2014 @04:41PM (#8044430)
One more thing: OCaml is strict by default, Haskell is lazy by default. The later allows for some nice code idioms[0], but makes reasoning about performance and memory characteristics very difficult[1].

[0] indexedList :: [a] -> [(Integer,a)] indexedList l = zip [1..] l

[1] http://www.reddit.com/r/haskell/comments/15h6tz/what_isnt_ha...

http://www.haskell.org/pipermail/haskell-cafe/2013-September...

http://stackoverflow.com/questions/2064426/reasoning-about-p...

Re:Why We Use OCaml by yawaramin on Thursday July 17, 2014 @01:46AM (#8046212)
Or even:

indexedList = zip [1..]

Love how ML-like languages let you express just the bare essence of an operation.

Re:Why We Use OCaml by spott on Wednesday July 23, 2014 @06:25PM (#8077283)
Yea, I didn't do that just to make it clearer: if you aren't used to ML, I Imagine that this would be very confusing.
Re:Why We Use OCaml by runT1ME on Wednesday July 16, 2014 @04:10PM (#8044245)
Neat reply, thanks.

In regards to #2, this sounds like the ST monad, are they comparable at all?

What makes OCaml easier to debug with GDB opposed to haskell specifically? I don't have experience doing either, but that's a curious statement, I would have assumed they were similar (both native code w/ some sort of GC...)

Re:Why We Use OCaml by tel on Wednesday July 16, 2014 @04:14PM (#8044270)
OCaml allows you to use mutation pervasively without marking your type. Haskell requires you mark your type with `IO`, `ST`, `State`. You can see Haskell as advantageous because it means that if you have a type without one of those markers you can be certain there is no observable mutation occurring. You can also see Haskell as disadvantageous because those markers are a little annoying.

The ST monad lets you transition from regions which allow mutation to pure regions and then back again.

Re:Why We Use OCaml by dllthomas on Wednesday July 16, 2014 @04:36PM (#8044399)
Basically, all OCaml code runs in IO. You can still only modify things that you've marked as modifiable (analogous to an IORef), but there is no constraint on where you can modify them from.

(In case it's unclear, I'm agreeing with tel and rephrasing.)

Re:Why We Use OCaml by orbifold on Wednesday July 16, 2014 @06:12PM (#8044907)
One advantage that gives you, is that you can easily define a monad on top of that and not worry about monad transformers. Jane Streets async library does that in its Deferred module https://ocaml.janestreet.com/ocaml-core/111.17.00/doc/async/...
Re:Why We Use OCaml by tel on Wednesday July 16, 2014 @06:28PM (#8044980)
But I like transformers... a lot!
Re:Why We Use OCaml by seliopou on Wednesday July 16, 2014 @07:24PM (#8045182)
Your Haskell program doesn't use the C stack, so using gdb may tell you something about the Haskell runtime you're using or some C library you called into, but it won't tell you much about the state of your actual program.