
OCaml for the Skeptical: OCaml in a Nutshell (2006) - ColinWright
https://www2.lib.uchicago.edu/keith/ocaml-class/class-01.html
======
smabie
I like Ocaml and it would be a good choice of language for most kinds of
projects, especially if good performance is desired. OCaml is dead simple to
learn (I always recommend it as the first FP language they should learn) and
eminently practical.

If you're coming from Haskell or Scala though, OCaml's type system is going to
come off as pretty primitive. And in many ways it is primitive, the idea of
"type-level" programming isn't really a thing in the OCaml community.

My favorite part of OCaml though is that the compiler generates fast, native
binaries, which in my opinion is reason enough to choose it over Scala or F#.
The language is on par with F#, but notably less expressive than Scala.

But if you want a simple language that anyone can pick up quickly, one with a
well defined performance profile and a practical, concrete ecosystem, OCaml
might be the perfect choice. Just don't expect a Haskell or Scala like
experience.

~~~
millimeterman
I don't know if I'd call OCaml dead simple. It's full of inconsistencies and
bolted-on features that are practically useful but definitely not simple or
elegantly designed. It's kind of like the C++ of ML derivatives in that sense.

I'd say Standard ML better fits the bill of "dead simple". The only issue is
that tooling and learning resources are nearly nonexistent.

~~~
andrepd
>full of inconsistencies and bolted-on features that are practically useful
but definitely not simple or elegantly designed

Care to elaborate? What are you referring to?

~~~
millimeterman
Just some examples:

\- First-class modules don't feel very first class, with how clunky it is to
use modules at the value level

\- Records are very clunky and hacky to use

\- Generative functors are a hack

\- Special language-level equality magic is awful (although SML also has this
problem)

\- Special `let` forms (whether via ppx or integrated into the language) feel
really hacky

\- GADTs require too much handholding of the typechecker

\- All the "Objective" parts have very few redeeming qualities and should
probably never have existed

\- The way infix operators work is really half-assed

I don't think OCaml is a _bad_ language - it's very practically useful. It's
just not simple or elegant.

~~~
ernst_klim
Words like "clunky" and "hacky" are evaluation judgments, not objective
criticism.

------
steev
This [1] is a a much more detailed course that gives a great introduction to
OCaml.

[1]
[https://www.cs.cornell.edu/courses/cs3110/2019sp/textbook/in...](https://www.cs.cornell.edu/courses/cs3110/2019sp/textbook/intro/ocaml.html)

~~~
johnisgood
There is also
[https://www.cs.cornell.edu/courses/cs3110/2019fa/textbook/](https://www.cs.cornell.edu/courses/cs3110/2019fa/textbook/).
Yours is 2019 Spring, this is 2019 Fall. This version covers many more topics.

------
modernerd
Is there a good reason to learn ReasonML instead of OCaml these days, or
should I just learn OCaml + js_of_ocaml?

I'm interested in building web apps, web servers, and simple WebSocket
servers. OCaml appeals to me because it has more escape hatches than Haskell
and is higher level than Rust, but I've always found the ReasonML vs OCaml
story confusing.

~~~
wk_end
I'm one of the weirdos who likes OCaml syntax, but in my eyes ReasonML is
unfortunate. It fractures the community for (ironically) no real reason - not
only is it a new syntax, they're now writing a new standard library for it
(Belt), as though the three existing ones (plus the JS one!) weren't enough! I
don't think the new syntax is particularly nice either.

I don't think js_of_ocaml supports any kind of JSX. That's the only real
reason to use Reason over OCaml that I know of, and it's a good one. But if
I'm being frank, even if OCaml/Reason is a nicer language overall, TypeScript
is a statically-typed frontend development story that has way more community
buy-in and way fewer rough edges in the ecosystem. Just use it.

~~~
modernerd
That's helpful, thanks.

The recent syntax switch[1] does feel like it will further fragment the
community.

And TypeScript has some pretty attractive functional projects:

[https://github.com/gcanti/fp-ts](https://github.com/gcanti/fp-ts)

[https://github.com/Matechs-Garage/matechs-effect](https://github.com/Matechs-
Garage/matechs-effect)

[1]: [https://reasonml.org/blog/bucklescript-8-1-new-
syntax](https://reasonml.org/blog/bucklescript-8-1-new-syntax)

~~~
brmgb
There isn't much to fragment to be honest.

From what I have seen, there seems to be little buy-in for Reason in the Ocaml
community which is not particularly surprising considering it's supposed to
solve a pain point no one in the community actually has (Ocaml syntax is fine
- it's obviously more Algol-like than C-like but clearly the existing
community doesn't care).

Reason seems to be mostly pushed by Facebook towards Javascript developers.
That might work. Then again, esy is nice.

------
jopython
Wake me up when OCaml get multi-core support.

~~~
shakow
They are actively working on it ([https://discuss.ocaml.org/t/multicore-ocaml-
may-2020-update/...](https://discuss.ocaml.org/t/multicore-ocaml-
may-2020-update/5898)) (HN discussion here,
[https://news.ycombinator.com/item?id=23380370](https://news.ycombinator.com/item?id=23380370)).

------
WalterBright
I tried to use OCaml once. My main difficulty was the compiler error messages
were very primitive, and I had an awful time figuring out what was wrong with
the code I was writing.

I finally just gave up.

~~~
yawaramin
Ah that's too bad, it really does offer an elegant and efficient programming
stack. Admittedly the syntax errors are historically bad but the editor
support tool, Merlin, offers more help with those, with messages like "Syntax
error after ... expecting `=' "

------
S4M
Last updated in 2006.

~~~
sweeneyrod
Yes, it has a very 2006-era "OCaml as an alternative to C/C++" attitude, hence
the claims that OCaml has an extensive library ecosystem and developer
tooling: compared to C this is true but not compared to Python/Java in 2020.

The suggested tools are also out of date. If you want to try OCaml nowadays
you should probably install it with opam and use dune as a build system.

------
ocamlskeptic
Curious question: If you are picking OCaml over Rust in 2020 for a new
project, what is your reason for doing so (other than being already familiar
with OCaml through college courses, or wanting to try out something new for
fun) ?

The only reason I could think of was being able to compile to JS, but other
than that Rust seems to be a superior choice for all the use cases I could
have used practically used OCaml for.

~~~
smabie
I've never really seen them as comparable. But I would choose Ocaml over Rust
because OCaml is easier, less complex, and more expressive. Also, Rust doesn't
support functional programming. OCaml's performance is really quite good and
I've never had problems with the GC.

Unless the project absolutely couldn't tolerate GC, why would I choose a low
level language like Rust over a high level language like Ocaml?

~~~
Ar-Curunir
Rust offers a better alternative to functional programming: you can mix and
match imperative and functional programming without the pitfalls of arbitrary
mutable state (which is where most attempts to mix and match run into
problems)

~~~
scns
OCaml can do the same

