OCaml Resources (2006)
www2.lib.uchicago.edu
www2.lib.uchicago.edu
OCaml syntax is super idiosyncratic and doesn't resemble anything, but, once you retrain your eyes, the underlying semantics are terrific.
js_of_ocaml imposes very minimal code overhead (6k-ish). Sourcemaps work great, and OCaml values are mapped into JS in a very straightforward way. You can read them in a JS debugger.
Ocsigen's lwt library is also the best "callback hell" solution I've found.
The only advice I can offer is that the documentation actually is correct and pretty complete, but there's nevertheless something about its organization that makes it difficult to find what you're after.
In particular, start by reading this page carefully: http://ocsigen.org/js_of_ocaml/2.5/manual/library
It explains everything at a high level.
After getting past the steep learning curve (about a weekend of pedal-to-the-metal debugging), I really got a feel for how beautiful OCaml semantics really are.
If you're looking for a solid and familiar OCaml stack, check out OWebl [0]. Always looking for helping hands or other support.
[0] - https://www.janestreet.com/
[1] - http://meetowebl.com
And because of my guess, what do you think of the performance?
I haven't got to the point of doing any benchmarks, but according to the author, it is slower than plain OCaml. I've only written a couple of toy programs (a Swing GUI in OCaml!)
I am, however, very impressed by the implementation. The author wrote an OCaml library that emits Java bytecode, and then modified the OCaml compiler to emit bytecode. He then ran the compiler on itself, and got an OCaml implementation on the JVM written completely in OCaml (plus some runtime classes in Java).
The author, who used to work at INRIA told me he's now working on a startup using OCaml-Java.
I want to make a joke about the F/L/OSS spirit of this guy, but the whole QPL thing has been repeated a la Shen in circles where I read and seems to have left a sour taste in the mouth of some, like this guy.[2]
Still, I am in place to judge OCaml devs or the community around them, as they seem increasingly awesome. I am a novice, but a CS undergrad in my hood specifically said check out OCaml when we discussed functional langs because of the Jane Street videos. And before that, my only expsoure to what OCaml was, let alone is or even coding it, was the eMule software package.
Anyway, good to see you on the field. If you are paying attention to this, I certainly will! [1] https://github.com/xclerc/ocamljava/issues/22
I feel that many of the advantages of switching to OCaml are minimised when you are already using an ML!
Soon, there should be a compelling performance case for using OCaml. There are rumours that in the next release, there'll be an MLton type whole program optimisation setup, which should reduce the cost of abstraction to zero.
MLs are such that the value-level stuff and the module-level stuff are more or less independent. So you can go a long way just liking the value-level stuff without really caring about the status of the module-level stuff. But it's also a pretty big motivator for the design of ML. F# is at least weirdly missing out here.
http://www.mpi-sws.org/~rossberg/1ml/
"a redesign of ML in which modules are truly first-class values, and core and module layer are unified into one language. In this "1ML", functions, functors, and even type constructors are one and the same construct; likewise, no distinction is made between structures, records, or tuples."
A good example is the Set.Make functor in the OCaml stdlib. Elements in a Set must be orderable for efficiency's sake, so to construct a Set you parameterize it over a module specifying not only the type but also its ordering.
module type Set = sig
module type OrderedType =
sig
type t
val compare : t -> t -> int
end
module type S =
sig
type elt
type t
val empty : t
(* ... *)
end
module Make :
functor (Ord : OrderedType) -> S
with type elt = Ord.t
end
Here the OrderedType module signature represents any type that also has an ordering. The S signature represents the result signature of calling the Make functor which is passed any OrderedType-substantiating module and uses it to construct the (Set.S with type elt = Ord.t) module.Maybe not for folks whose primary platform in Windows? The .NET stack is the primary advantage there, no?
For those of us on Linux, IMO OCaml is the similar language with complete platform support. I know .NET core is now available, but some time will have to pass to know if Microsoft's support for .NET on Linux is a long term plan.
I guess the official homepage http://ocaml.org would be better for up-to-date information.
https://github.com/realworldocaml/book/wiki/Installation-Ins...
* OPAM for package management * Utop for a REPL * merlin for autocomplete and type queries * ocp-indent for aotomatic indentation
That say, the type helps from Tuareg/merlin and a few other things really started to become very handy, and I miss them in ClojureScript now.
[0] "Early OCaml workflow pains" - https://www.youtube.com/watch?v=rDFocxR6Mpw
I couldn't shake the feel that I was learning "Haskell Light". No pure/impure code (I/O, mutable references, exceptions), no monad syntax sugar, less syntax sugar for pattern matching, much smaller base library, plus surely other differences that my current level of expertise of Haskell is hiding.
Perhaps the simpler semantics make it easier to translate to js (I know haskell->js transpilers are very complex and I'm sure lazy evaluation has a lot to do with it), but in terms of language features, what am I missing in Haskell that makes you more productive/helps you write clearer code in OCaml?
- There are good conventions for naming and argument order (and named arguments!) so I don't have to memorize a bunch of different APIs. This is made possible by the module system. It could probably be solved in Haskell with better tooling.
- Modules allow you to, for lack of a better word, make your code more modular. Modules are essentially the same thing as what people use objects for in Java. They let you abstract implementation and program against a particular interface (i.e., a collection of types and values) easily in a way you can't really in Haskell.
Haskell type classes can make it a bit easier to encode (and infer) interfaces but assume a single implementation per data type. ML modules do not make this assumption and support a higher degree of modularity as a result.
Robert Harper has some extremely good writing out there on this topic (and many more): https://existentialtype.wordpress.com/2011/04/16/modules-mat...
[0] - http://www.mpi-sws.org/~dreyer/papers/mtc/main-long.pdf
A good example of something easy to do with ML modules and hard to do in Haskell is the Cohttp library which is a HTTP stack that works using the Lwt async backend, the Async async backend, and a Javascript Lwt backend. It is merely modularized over that interface and you can plug in whatever backend you like.
There are examples of doing similar things (Reflex is modeled this way, e.g.) but it's hairier in Haskell.
First of all the word "compiler" is perfectly adequate to convey the meaning of a "transpiler", meaning a computer program whose purpose is to translate code from one programming language into another. The usage of the word "transpiler" only happened because of languages like CoffeeScript, as a word was needed to express that CoffeeScript is just as broken as Javascript, but with syntax changed for no good reason.
But more importantly, many compilers that target Javascript, such as Scala.js, ClojureScript, GHCJS, Dart, are very much not like CoffeeScript, meaning that we are talking about languages with different type and module systems, with big standard libraries, that treat Javascript as bytecode and that need to be compressed with Google Closure to be viable. If you're missing the source-maps, the end result will be much harder to understand than Java or .NET bytecode. Therefore the usage of the word "transpiler" in this context is not only annoying, but incorrect as well.
Our students were mostly having trouble with OCaml being a functional language than anything else. Some of them independently discovered mutable references and for loops and probably wondered why we hid from them such useful constructs! Pattern matching was also something that only the best students took serious advantage of.
That said, it's definitely an even harder sell than F# in the corporate space.
Anyway, I've got a couple side projects, one of which is website in Go. How's OCaml for web development?
I also saw oCaml for iOS but it didn't seem to be up to date: http://psellos.com/ocaml/compile-to-iphone.html
Have a look at: https://github.com/mirage/ocaml-cohttp
You can of course also use cohttp directly but it's a little raw.
There is work underway to improve cross-compilation support [1][2]. Once that lands in a release, there shouldn't be any reason to maintain forks of the compiler for iOS, Android, etc.
I have to install msys2 and keep compiling by hand.
Even if a source solution that kept updating even if I had to compile regularly, would be preferable.
This is my only hesitation.
Please do feel free to join the group and give your 2 cents about the direction that this should take: http://lists.ocaml.org/listinfo/wg-windows
The Mirage library OS is a pretty serious project. Facebook also uses OCaml for Flow and the Hack type checker. And of course, Jane Street Capital uses OCaml.
But I'm guessing what you mean is that OCaml is a very non-mainstream language, so it will be rejected for most corporate projects just because it's so foreign.
Rather than snidely guessing what I meant, why not just read the rest of my comment or ask for clarification like an adult? Also, I'm not denying there are a few odd projects here and there that use it successfully -- as well as Jane Street, of course, who are almost synonymous with OCaml. But like I said, although it is a very nice (and educational) language, I just don't feel like it is "best of breed" in any particular area. Not sure what that has to do "corporate projects", etc.
You're right; I'm sorry.
And, well... I'm not really satisfied with it. OCaml produces a small amount of code, but is really slow and hard to understand. Sometimes, it looks like obfuscated code!
Documentation and libraries are not polished, and I would recommend Haskell instead of OCaml. Good for research and some algorithms, bad for applications.
And... God... "This page was last updated on 17 June 2006."
OCaml is slow? and your recommendation is to use Haskell instead... That doesn't compute well if we were to assume that you are writing some compute-intensive tasks for which (unoptimized non-C language can be "slower".
It more likely the case that students hate whatever languages the university teaches in place of language-de-jour. (Just read the reviews of SICP on Amazon).
And yes there are pages on the internet that are older than 2006, so what? No one goes "Pffft.. this is 300 years old.." when they come across Newton's Principa.
The difference is that programming languages evolve all the time. Having such an old page still up and promoted to the front page of Hacker News tells everyone that OCaml hasn't evolved since 2006.
Please don't be so sharp, I really don't understand why this link is in HN, and I'm just exposing my point of view, after practising OCaml a lot. So what, I'm a student so my opinion is worthless?
When you are starting out, convenience and familiarity (which are visceral) can trump abstract notions like "pure", "correct", "reason-able".
I'm not saying your opinion is worthless, just that your judgement could be coloured by inexperience.
My sincere recommendation is to use "Real World OCaml" - https://realworldocaml.org/ as a reference to learn OCaml instead of old and busted tutorials littering the internet. Trust me, I have been trying to learn OCaml "on the side" for a few years and RWO is the first book that I have absolute love (even accounting for a wide variety of PL books I read) for being practical, current and explaining stuff.
Do you have some examples of well-known applications built with OCaml? I'll have to check that too.
Do you mean that OCaml produces small binaries, or that the language itself is compact? As for being slow, that's the first time I hear this charge being leveled. Single-thread performance is usually really good.
1. "unfamiliar" syntax. Well... It is unfamiliar if your first exposure to programming stopped at Java. Guess what .. pattern matching is quite an old convention in programming languages old (Prolog, Erlang, ML, Haskell)... and new (Rust, Swift)..
2. Standard libraries are a crap shoot... cruft accumulates in standard libraries just like any piece of software but harder to clean up owing to demands of backward compatibility. Just go and look at Python standard library. Even on a superficial level, the stdlib is a mix of CamelCase and under_score .. which can be irritating.
OCaml is not unique in this regard.
It's a one line function to write, but it certainly has no business being in the standard library.
It's worth noting, however, that I've had very, very few problems with the semantic properties of the language. I think the slog is worth it for that reason.
Well, the reason is that Caml predates those ecosystems; the original Caml was released nearly a decade before Java [1], and ML itself dates back to the 1970s.
Talk of syntax is almost always history and religion, not science.
Also, this page is almost ten years old.
Not sure how this kind of post ever makes it to the front page.