Hacker News new | ask | show | jobs
by rubiquity 4018 days ago
It's cool to see a link about learning OCaml so high on HN. I started teaching myself OCaml a few months ago and I really like it. Here's a few things I like so far and why I think anyone that uses Go or Rust should give OCaml a look:

1. OCaml compiles to a binary like Go and Rust do

2. The type system is helpful without being a huge burden on learning/productivity (unlike Rust and Haskell)

3. Garbage collection

4. Pattern matching and algebraic data types (like Rust)

5. OCaml is plenty fast at CPU bound work(slower than Rust, faster than Go) despite not being parallel (yet)

Those are my takeaways of what I enjoy about OCaml so far. It has been the most approachable typed functional language that I've looked at yet! Depending on the type of things you want to learn and problems you want to solve, Your Mileage May Vary.

4 comments

Rust was originally implemented in OCaml, and takes a lot of cues from the ML family, as you've noted.
My power combo is F# and Rust. F# is fairly fast, has great tooling and rather expressive. And for the parts I need the speed, Rust fits in nicely. I can keep safety, while maintaining decent expressiveness. Something like Rust is needed, because when you need manual memory control, you really need it. With F#, I could measure the impact of every single allocation, even though short lived GC items are cheap.
Does F# have easy C interop, so you can call into Rust easily like you can from say, Python?
C interop is quite easy from .NET languages. Here's a simple example in F#:

https://msdn.microsoft.com/en-us/library/dd393785.aspx

That example is a bit Windows specific, but it works similarly with Mono on Linux and OS X:

http://www.mono-project.com/docs/advanced/pinvoke/

Those examples there are in C#, but PInvoke works almost identically in F#.

>1. OCaml compiles to a binary like Go and Rust do

And Haskell.

>2. The type system is helpful without being a huge burden on learning/productivity (unlike Rust and Haskell)

What? The type system is partly why my coauthor can use Haskell, unlike JS or Java. Haskell was her first time ever programming and now she's teaching Haskell to her 10 year old son.

I use Haskell in my day job, I couldn't do my job without the type system!

So in terms of learning and productivity in Haskell (can't speak for Rust), I will strongly disagree here.

The rest of the points apply for Haskell as well.

Haskell doesn't need to be hard to learn at all, it hasn't had the learning resources it deserves and expectations weren't being set properly. It's more like learning a new way to program (functionally) rather than a dialect of an existing paradigm (imperative, but we give you a map and a reduce function).

That paradigm (functions alone) is very simple but the implications are non-obvious and require a method of introduction that involves a lot of exercises.

I'm sorry if this sounds rude, but what's the point you're trying to make? I can't quite figure it out.
OP suggests Haskell's type system interferes with productivity. GPP disagrees.
If I could go back and remove one word from my post it would be the word "Haskell" because at the time I wrote it I suspected it would incite a reply like yours.
> OCaml is [...] faster than Go

On what basis do you say this? I'm not claiming to know the answer, but the (terrible) internet benchmarks I can find put them roughly neck-to-neck.