top | item 45846124

(no title)

laszlojamf | 3 months ago

I don't really get what's special about OCaml with these points they raise? Wouldn't almost any strongly typed language do? Wouldn't TypeScript also tick all these boxes?

EDIT: I wouldn't choose TypeScript either for this type of use case, but not for the reasons they state, that's my point

discuss

order

phplovesong|3 months ago

Typescript (javascript) is kind of a joke compared to what ocaml brings to the table.

Ocaml has a top in class typesystem, a "faster than Go" compiler and (in 2025) good tooling. It allows you to say fuck it and write a while loop if you need to. Hell you can even do OOP. Also it has an incredible module system and full type inference. It also has an effect system, and good concurrency features (ocaml 5).

I cant say many other languages that has all the same features.

jacquesm|3 months ago

It's the combination with concurrency that makes this a hard problem.

And OCaml excels at solving that sort of problem. OCaml and Erlang are the only two languages that I'm aware of that have a really clean way of doing this, in most other languages there is always some kind of kludge or hack to make it work and at best you're going to do something probabilistic: it seems to work, even under load, so it probably is good now. Until six weeks later on an idle Tuesday the system deadlocks and you have no idea how it happened.

internet_points|3 months ago

What advantage does OCaml have over Haskell here? I find software transactional memory in Haskell so simple to work with that I have lost all fear of concurrency, but what am I missing out on?

greener_grass|3 months ago

• Stategraph manages Terraform state, so correctness isn't optional

TypeScript has soundness issues that OCaml does not have

• Strongly-typed data structures catch field errors at compile time

TypeScript does have this, although the guarantees are in practice weaker since libraries may have incorrect type definitions

• Type-safe SQL queries prevent schema drift before deployment

There are TypeScript libraries that offer this, so fair point!

• Immutability by default eliminates race conditions

TypeScript is not immutable by default

• PPX generates correct JSON serialization automatically

TypeScript does not have an equivalent to PPX infrastructure AFAIK. If there is, it's definitely not as widely used within the ecosystem compared to PPX for OCaml.

Edit: Downvoters care to respond?

pjmlp|3 months ago

Besides the better type system, OCaml is a compiled language, you don't need workarounds like rewriting code in Rust and Go, as it happens on TypeScript/JavaScript world.

sausagefeet|3 months ago

Certainly there are specifics between the type systems that differentiate. TypeScript generally chooses to enforce types in an ergonomic way whereas OCaml chooses to enforce types in a sound way. Whether or not that is a meaningful differentiator for someone is up to them.

This blog post shows the elements of OCaml that motivate us to use it. Is it complete? No. Maybe it should be more explicit that we like using OCaml, and these technical aspects aren't unique but certainly benefits we see.

gregwebs|3 months ago

Functional programming is immutable by default. TypeScript and many other typed languages don't really stop you from clobbering things, particularly with concurrency. Rust does. But immutability with GC is a lot easier to use than Rust if you don't need the performance of Rust.

pjmlp|3 months ago

That is only true since people started equating FP with Haskell.

OCaml as the discussion subject on this thread, allows for mutable data structures, and I am old enough to have been taught Lisp as one possible avenue for FP.

galangalalgol|3 months ago

But what is functional besides haskell? Purescript? Elm I guess. Ocaml is not. It has for loops even. You can write pure functional ocaml but people don't. It mattered a lot less when it didn't have true concurrency, but now clobbering things in ocaml is quite possible.

IshKebab|3 months ago

OCaml has a much stronger type system than Typescript.

The real question is "why not Rust?". I've used both a fair bit and OCaml's only major advantage IMO is compile time. That doesn't seem compelling enough to put up with the downsides to me.

sausagefeet|3 months ago

I'm the CTO of Terrateam. For "why not rust", I have found the downsides of Rust not compelling enough to use it. We don't need close-to-metal performance. We don't really need the borrow checker, a GC is fine. We are immutable by default so the borrow checker doesn't help much there.

linhns|3 months ago

I don’t like OCaml myself, but I’d pick it over rust here as bare metal perf is not necessary, and time wasting fighting the borrow checker is just not worth it.

toolslive|3 months ago

Ocaml has a garbage collector. It's less of a struggle than Rust.

pjmlp|3 months ago

Answer is easy, not everyone needs the performance boost provided by borrow checker, 99% of the time some kind of automatic resource management is good enough.

jitl|3 months ago

Rust is a pain

phplovesong|3 months ago

Rust has too many footguns. Ocaml is usually more safe.