5 ms·
Comparing OCaml and Standard ML
- sgeisenh 12y agoPurity is almost used in a pejorative sense throughout the page. If it wasn't for poor library support, I would prefer using SML to OCaml. SML is syntactically simpler and both SML/NJ and MLton have a lot to offer that I haven't yet found with OCaml. I think one of the biggest mistakes in the life cycle of SML was premature specification. As a result of the language definition, SML has stagnated for almost 20 years. There is now some notion of "Successor ML" (see: http://sml-family.org/ http://sml-family.org/), but I honestly don't see it catching on outside of an academic space. As an academic language, SML is great. It is a great tool for learning functional programming since the learning curve isn't especially steep. It is easy to reason about performance since evaluation order is explicit. And immutability is the default but with mutable types that are easy to use.
- marktangotango 12y agoI really liked SML and wanted to use it in anger after reading "ML for the working programmer" and "Purely functional data structures" (excellent functional programming books by the way) but just couldn't due to the lack of libraries as you say. For me the object system on Ocaml was just too much. Tis a pity.
- Raphael_Amiard 12y ago> For me the object system on Ocaml was just too much What do you mean by that ? The current consensus about the object system in OCaml is "don't use it", even if there might be cases where it will describe your system better. The standard library (both the real stdlib and Jane Street's Core library) don't use objects so you can pretty much ignore this part of the language if you want to.
- marktangotango 12y agoSince that is the 'current consensus' as you say, it seems like the ocaml community converged on the opinion I formed 10 years ago. But it wasn't necessarily the consensus then.
- Raphael_Amiard 12y agoOk, makes perfect sense !
- avsm 12y agoThere's nothing wrong with objects or classes in OCaml -- it's just that most problems can be expressed using a simplest abstraction technique such as modules. OCaml has steadily improved in every recent release to further reduce the set of problems that need objects (open types, GADTs, first class modules, destructive substitution in module types). For problems where objects and classes are a good fit (e.g. something requiring open recursion), then OCaml objects are fine and sound. They are used quite nicely in CIL for implementing the visitor pattern, and I like them in the Lablgtk OCaml bindings as well. They also provide a nice bridge to foreign code in OCamlJava and js_of_ocaml when compiling to platforms that make more use of objects. It's worth noting that class types and object types are distinct in OCaml, so you can often use objects without involving classes at all. This is explained in Real World OCaml: https://realworldocaml.org/v1/en/html/objects.html https://realworldocaml.org/v1/en/html/objects.html Not using OCaml because it possesses an optional object and class extension is a little strange. It never really gets in the way...
- pjmlp 12y agoI remember reading that book on my crossings over the tagus river in Lisbon, after we got introduced to Caml Light. Time flies!
- larsberg 12y agoI agree completely with your library statements. > I think one of the biggest mistakes in the life cycle of SML was premature specification. I disagree. There were some earlier Successor ML efforts ~10 years ago (see: http://successor-ml.org/index.php?title=Main_Page http://successor-ml.org/index.php?title=Main_Page ), but as I understand it, there was agreement on many of the small issues but larger challenges reaching consensus on bigger changes. You can see some notes from Bob Harper at the ML Workshop in 2013 on how we're moving forward currently: http://www.cs.cmu.edu/~rwh/talks/mlw13.pdf http://www.cs.cmu.edu/~rwh/talks/mlw13.pdf
- bjz_ 12y agoThat's certainly a pretty exciting presentation! Looks like a huge effort though... how much progress has there been since?
- larsberg 12y agoWe did the first part and very recently put http://www.sml-family.org/ http://www.sml-family.org/ online and announced the opening of the definition (whew!). I'm primarily concerned with the parallelism and concurrency-related features, which we're trying to first clean up a bit more in the context of Manticore before trying to do something like proposing standardization for those features. Also (IMO) you should take those slides more as a research direction for years of research investigating alternatives that eventually get standardized, not a 2015 implementation plan :-) Each of those topics casually mentions non-trivial extensions to problems that already have each had researcher-decades of investigation.
- ajb 12y agoGiven the goal of implementing proof systems, whose semantics you obviously need to be really clear, I don't think that specification was premature. But you're right that it has inhibited the use of the language in a more general setting.
- jdh30 12y ago> SML has stagnated for almost 20 years I'm still waiting for OCaml to get decent multicore support, decent Windows support and an FFI that doesn't suck donkey brains through a straw (which is why so many OCaml libraries, like OpenGL bindings, suck beyond belief). Multicore became ubiquitous 10 years ago. Last I looked the vestigial OCaml community still hadn't noticed.
- adultSwim 12y agoThe netmulticore library [1,2] worked well for me. The style there is to spawn worker processes and pass messages between them. I'm not sure how popular that library got but that style of programming seems to be pretty popular among OCaml users who need it. Many projects use something lighter-weight or just roll their own (e.g. Parallel in Jane Street's ocaml-core looks pretty good [3]). I certainly wouldn't mind if you could swap out the garbage collector (a la Java - where you can choose between a fast serial garbage collector and a parallel garbage collector). However, I don't think it's the right tool for many tasks. [1] http://blog.camlcity.org/blog/multicore1.html http://blog.camlcity.org/blog/multicore1.html [2] http://projects.camlcity.org/projects/dl/ocamlnet-4.0.0test2/doc/html-main/Intro.html#netmulticore http://projects.camlcity.org/projects/dl/ocamlnet-4.0.0test2... [3] https://ocaml.janestreet.com/ocaml-core/109.24.00/doc/parallel/Std.html https://ocaml.janestreet.com/ocaml-core/109.24.00/doc/parall...
- edwintorok 12y agoHave a look at the 'Multicore OCaml' presentation here: https://ocaml.org/meetings/ocaml/2014/ https://ocaml.org/meetings/ocaml/2014/ TBH I don't miss multithreading in OCaml, if you write applications which expose some sort of API over a socket that will scale to clusters, not just multicore. And you can program those kinds of applications quite nicely with Lwt or Async already. Regarding FFI, ocaml-ctypes is interesting, it allows you to bind to a C library at runtime using pure OCaml (and a wrapper around libffi), or to generate C stubs. Regarding OpenGL there is a new binding called 'tgls' for OpenGL 3.x/4.x (besides LablGL) that is mostly generated from the XML description of the OpenGL APIs. Regarding Windows support I can't say much because I don't use it at all, but there was a new 'Self-containted OCaml distribution for Windows' called ocpwin-distrib posted to the ML recently. If you care about Windows support you should probably give them feedback on what is missing.
- adultSwim 12y agoI would note that several SML extensions were made by adding on to existing compilers (e.g. Concurrent ML). The Haskell community has used this model to great effect (testing/refining new features as add-ons to existing compilers and then moving some of them into the main language). Any ML would be good. The basic features of the language are the best. "Vanilla" ML would suit most people's needs (preferable replacement to many popular languages).
- p4bl0 12y agoSmall update: recent versions of OCaml have immutable strings too. It also miss mention of package manager (OCaml has Opam, which is awesome, I don't know about SML). And ocamlbuild is missing from the build tools section.
- yodsanklai 12y agoOut of curiosity, why do you think Opam is awesome? I recently had to install a few OCaml projects and I had a hard time dealing with opam and ocamlfind (both on mac os and a linux VM). I suppose it's fine once everything is properly set up. I have the impression that the OCaml world has seen a lot of changes recently with a lot of complexity added.
- p4bl0 12y agoI think Opam is very cool because it simplifies OCaml development a lot, just like any language package manager does for its language. With Opam I can deploy my code on different machines very easily by installing the right version of OCaml and library dependencies in just a few command, and it just works. The problem with ocamlfind you are mentioning was just a temporary bug I think, I also encountered it, but it will be fixed real soon, see: <https://github.com/ocaml/opam/issues/1671> https://github.com/ocaml/opam/issues/1671> for instance.
- mercurial 12y agoI find 'ocaml switch' very useful (sandbox functionality). Also, you can add a repo for your local stuff very easily. The CLI is pretty nice and well-designed.
- amirmc 12y ago> I have the impression that the OCaml world has seen a lot of changes recently with a lot of complexity added. The first part of that is very true but the second part feels completely and utterly false to me. Where is this added complexity? OCaml and OPAM were ridiculously trivial to set up on my system (via homebrew on a Mac) and OPAM 1.2, with many improvements, is due for release in the next few days [1]. Decent instructions are in the RWO wiki page [2]. The OPAM devs are responsive to bug reports and do a lot to maintain the health of the package ecosystem too. If you're installing everything from sources then you're choosing to take on that burden and I wish you well but don't claim that more complexity is being added. [1] beta announcement: https://opam.ocaml.org/blog/opam-1-2-0-beta4/ https://opam.ocaml.org/blog/opam-1-2-0-beta4/ [2] https://github.com/realworldocaml/book/wiki/Installation-Instructions https://github.com/realworldocaml/book/wiki/Installation-Ins...
- zvrba 12y agoOcaml: the practical and the ugly one. (I hate Ocaml's syntax mainly due to the noise of let ... in clauses)
- CmonDev 12y agoWow, ML syntax is actually better than OCaml. It's a shame the former was used as a base for F#.
- mercurial 12y agoReally? I can see how it's nicer in some places, but you'll take currying and or patterns out of my cold, dead hands (and there are some cases where you do need objects).
- profquail 12y agoOne thing I think F# got right is that it removed some of the "flexibility" in OCaml's syntax. For example, it uses significant whitespace to define scoping, which removed (in nearly all cases) the need for the 'in' keyword and lots of parentheses and semicolons. That may not sound like a huge deal, but it does greatly improve the readability of F# code (all other things being equal).
- pjmlp 12y agoActually when F# was introduced, you could switch between both modes. After voting the #light "on" became the default behaviour. You can get the more compatible OCaml one with #light "off".
- jdh30 12y ago> One thing I think F# got right is that it removed some of the "flexibility" in OCaml's syntax. For example, it uses significant whitespace to define scoping, which removed (in nearly all cases) the need for the 'in' keyword and lots of parentheses and semicolons. That may not sound like a huge deal, but it does greatly improve the readability of F# code (all other things being equal). I must disagree. I once translated a significant (15kLOC) commercial OCaml code base into F# and took the opportunity to quantify the syntactic benefits as <3% by volume of code. The flipside is that F# misinterprets code pasted from the web, rendering most code on the web useless. That is a crippling deficiency of F# in my eyes and a major reason to go back to the superior OCaml solution.
- jdh30 12y ago
- a0 12y agoML's syntax is indeed less confusing than OCaml's. And that's the reason I'm working on a compiler front-end replacement for OCaml inspired by Clojure, Haskell, Ruby and Julia. It will be for OCaml what Elixir is for Erlang. I'm finishing the parser right now and will next implement the language primitives as a library in the language itself.
- mercurial 12y agoI'm curious about what you find particularly confusing about OCaml. I'm a (relative) newcomer to the language, but I find it extremely readable, even if it's a bit clunky at times.
- tomp 12y agoWhat does this code do? if a > 0 then print_endline "a > 0" ; match a with | 0 -> print_endline "impossible" | 2 -> match b with | 0 -> print_endline "2, 0" | _ -> print_endline "2, not 0" | 3 -> print_endline "3, something" | _ -> print_endline "something, something" ; print_endline "done"
- p4bl0 12y agoAny decent programming editor will be able to indent that properly and you will see the problem. Also, I agree that it is a bit ugly but it's not that complicated to understand how the match syntax works. Adding a "begin" and an "end" in this code is simple enough :).
- tomp 12y agoIt's not just the match syntax; it's also the `;` expression separator. > Any decent programming editor will be able to indent that properly and you will see the problem. This seems like a weak excuse. In particular, I could turn it around and say, "any decent programming language should be writable without an editor". Also, the issue isn't just reading, it's writing too - it's much harder to foresee/plan all the `begin`/`end`, while you're writing a line of code, that will make the lines that follow work as intended.
- gnud 12y agoI really enjoy working with SML (I've used sml/nj and parrotml) - and would love to use it for "real" projects, but until it actually has decent unicode support, there's just no way I can.
- agumonkey 12y agoSml syntax is indeed very nice, and emacs sml-mode is pretty strong too. A great joy to use, almost as good as paredit.
- Altenuvian 12y agoincluding mythryl, a sml/nj derivative with c-flavored syntax to the comparison would be interesting. see http://mythryl.org/ http://mythryl.org/ for further info.
- Altenuvian 12y agoups - copy and paste error - this should have read: it would be interesting to include Mythryl to the comparison.