Hacker News new | past | comments | ask | show | jobs | submit login
So you're learning OCaml (hyegar.com)
142 points by e_d_g_a_r on Oct 20, 2015 | hide | past | favorite | 48 comments



If you are interested mainly in the functional language aspect of OCaml and use Windows, F# is very close to OCaml in syntax/semantics, but has really good support within Visual Studio (a really good debugger for example).

Once you want to use some of the more advanced features (Modules and Functors come to mind), you can switch back to OCaml relatively easily since they are so similar.


Any good books or resources for learning F#?



I second that along, with fsharp.org and tryfsharp.org.


I like Real World Functional Programming by Tomas Petricek if you are already doing C# development.



I love OCaml the language, but the tooling, especially wrt building (ocamlbuild, Oasis etc) , is horrendous. That said, the situation is much better now, than say 5 years ago.


Some of the tooling is really great, e.g. opam Just Works, utop feels very comfortable and merlin is amazing[1].

The lack of a standard build system is annoying yeah; I tried for a while to make do with just ocamlbuild and a Makefile, but eventually gave in and learnt Oasis, and it does the job just fine for my purposes, just feels a bit messy (compared to something like cabal, which at first sight hides a lot of the intermediate steps).

[1] http://the-lambda-church.github.io/merlin/destruct.ogv http://the-lambda-church.github.io/merlin/merlin-vim.ogv


Agreed.

FWIW I basically use the same _oasis file over and over again, it literally takes only 5 minutes to set up a project's needed boilerplate, _oasis, .merlin and opam directory.


Is there any good guides on how to do this? Or are your oasis template files shared online?


I just amended the blog post with a cradle to grave example of creating _oasis, .merlin and opam directory for any OCaml project.


Very useful. Thank You! I basically gave up on OCaml for anything but toy projects, but I may re consider that decision if this works for me.



An OCaml MOOC just started yesterday, I think there's still time for people to get in:

https://www.france-universite-numerique-mooc.fr/courses/pari...

Session 0 is just a lot of introductory stuff (history of OCaml, etc.), so it shouldn't be difficult to catch up.


Is there a way to watch the classes and other course material without registering?


The registration is free, unless you are weary of sharing your email with a university

(which are pretty good at guarding their students' privacy.. though you should definitely check their policies before signing up)...


I'm in this course I've been interested in the ML family of languages ever since learning SML which is without a doubt my favorite language ever.


I really wish there were an implementation of SML that got some traction. It's a lovely language, but has very few libraries for actually getting anything done.


I do not think it is too late for SML necessarily. MLton (the full-program-optimizing compiler) is very competitive with the (one) OCaml implementation.

As someone who did a lot to market certain OCaml libraries, I have seen similar interest in some of the "modern" SML libraries I have played around with. Not a ton of work has gone into both of these, but you may be interested to look at two projects MonoML[0] and SSMLS[1].

These are some /very/ minimal projects I've worked on in SML in the past few months to gauge how well SML might work as a modern, web-friendly, higher-level language. The results are certainly not completely disappointing.

Edit: Oh also! HamletML[2] (yes, written by the 1ML guy) is a very interesting ML implementation that would probably be a great way for work on modern language features. Not that I know what I'm talking about, but it could also provide the framework for an even more powerful backend/optimizing compiler.

[0] https://github.com/eatonphil/monoml

[1] https://github.com/eatonphil/ssmls

[2] https://www.mpi-sws.org/~rossberg/hamlet/


Unfortunately, SML has no industrial users. At least, that I've heard of. It's a language that's used mostly in teaching and academic research. First ML I used was SML/NJ in my intro CS class, and haven't seen it since. Whereas OCaml has a many industrial users and is widely deployed. My favorite example is of course management layer for the Xen hypervisor[0][1], but there are more as well[2].

Adam Chlipala has a writeup[3] on comparing SML and OCaml that may be of interest to the discussion.

[0]: https://github.com/xapi-project

[1]: http://anil.recoil.org/papers/2010-icfp-xen.pdf

[2]: http://ocaml.org/learn/companies.html

[3]: http://adam.chlipala.net/mlcomp/


What do you think about Manticore? I'm curious.


Maybe Rossberg's 1ML will become a reality.

Barring that, "Successor" ML is cleaning up some deficiencies in the original standard, and ML implementations are starting to integrate the changes.

But yeah, a strict ML with the pristine syntax of SML; the modular implicits coming to OCaml; the innovative ideas in 1ML -- now that would be a great language.

Sigh, back to Scala...


There's Manticore being developed by University of Chicago.


I like OCaml very much, though I haven't written code in it in the last 10 years, when I taught myself the language a long time ago I very much enjoyed it. I preferred SML/NJ, but that never got any velocity.

It'd be nice to have a job working in OCaml.


Does anyone know any good GUI OCaml IDE for Mac (something like RStudio)? Because the plugins for Eclipse and Intellij aren't very good and ocaml-top doesn't seem to work.


None exist. So far the best solution is to use Emacs with [2]

* merlin-mode, for autocompletion

* ocp-indent, for external code formating... think running gofmt on every enter press (surprisingly, it's fast enough unless your file is 2k lines long)

* tuareg-mode (everything else, REPL etc.)

* flycheck-ocaml for syntax checking

The "real" IDE plugins aren't even close and that's saying a lot since the hodge-podge of addons I just listed isn't

The default Emacs user experience is awful so if you're a Vim user, just install the "evil" package and enable it inside Emacs by doing M-x evil-mode, then you have Vim inside Emacs. Or use Vim, but the experience isn't as complete w.r.t. tooling[3]. There's always Spacemacs as well[1].

[1] https://github.com/syl20bnr/spacemacs

[2] https://github.com/the-lambda-church/merlin/wiki/emacs-from-...

[3] https://github.com/the-lambda-church/merlin/wiki/vim-from-sc...


Thanks for the links! I am currently using Sublime Text with the merlin plugin, which is pretty good. But I guess I should learn emacs to use OCaml.


Stick with Sublime Text. As long as you have merlin, the rest doesn't matter.


Second Drup here, merlin is the key feature. (I didn't know sublime had a merlin plugin)


Yeah it's this one: https://github.com/cynddl/sublime-text-merlin (The one on Sublime Package Control is the same, but seems to be out of date and doesn't work).


Vim works well enough for me. I got merlin-mode, ocp-indent and syntax checker to work in vim but not REPL.


Swift has lots of ML heritage, tho' not as much as F# obv


While digging for history I read these slides from David Turner (miranda and other, pre-haskell)

http://www-fp.cs.st-andrews.ac.uk/tifp/TFP2012/TFP_2012/Turn...

It's not directly related to OCaml, but it retrace the roots of the ML family too, so I thought it could be of interest.


Yes, I'm learning an OCaml dialect. It's called Rust, it's really interesting, you should take a look at it.


I feel embarrassed while reading your comment as a Rust proponent... Promoting Rust is great at times, but this particular article doesn't really have anything related to Rust. It is true that Rust was much influenced by OCaml, but the influence is not to a degree of calling it a "dialect". I'd say F# is much more likely a dialect of OCaml.


Is there a good reason to say that Rust is an OCaml dialect?


I'd describe it more as uglyfied Haskell, but anyway: http://science.raphael.poss.name/rust-for-functional-program...


It really doesn't have that much in common with Haskell either. It's designed by people who are not oblivious about PL stuff, but it's still pretty thoroughly in the C/C++ world in terms of both syntax and semantics.

It's not a bad thing, but Rust has very little in common with Haskell/Ocaml; aside from stealing a couple of good ideas.


I would say Rust's type system has a lot more in common with Haskell/Ocaml than with C++, at least, although it's not quite as flexible as what Haskell offers (a lack of HKT is painful sometimes).


I think the similarities are mostly superficial. I mean it has (local) type inference, ADTs, and traits (which are sooooorta like type classes). But, as a Haskell programmer, the Rust type system feels very foreign.

No typeclasses (and associated goodness), GADTs, HKTs, Monadic IO, first class functions, generic deriving, higher rank types, existential type, etc. These are bread-and-butter features in day-to-day Haskell work. Rust's type system isn't powerful enough to build the vast majority of the tools that Haskell programmers use every day.

I don't mean this as a criticism; The Rust design seems solid. But different priorities lead to different trade-offs, and the end result is a very different type system.


Traits do a lot of what one can do with typeclasses (they're mostly just different names for the same thing), what differences are you thinking of?

Also, traits objects are existential types, and closures & functions are as first class as they are in Haskell (main difference is a bit more verbosity).


No more than saying Erlang is a lisp dialect.



> Is there a good reason to say that Rust is an OCaml dialect?

There is, maybe, grounds to say that all languages with S-expressions, first class functions and garbage collection are just a type of lisp.

But I would not say that all languages with strong static typing, some form of type inference, algebraic data types, patterns matching and functional programming features, are a dialect or OCaml, or ML.


It has algebraic data types, type inference, closures, pattern matching.

Haskell has these too, but it has more stuff like more emphasis on immutability and purity unlike Rust and OCaml.

Also, the first Rust compiler was written in OCaml.


waiting for the "rust is an acceptable ml" blogposts!


Ah, I'm currently learn some ruby/java/c/haskell/go/erlang/javascript, should I learn the Rust dialect instead?


Have fun spoon feeding those type annotations!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: