Live data from Hacker News

OCaml as my primary language

xvw.lol

141–150 of 296 posts

Re: OCaml as my primary language

#141

I saw a talk by someone from Google about their experiences using Rust in the Android team. Two points stuck out: they migrated many projects from Python, so performance can't have been that much of a concern, and in their surveys the features people liked most were basics like pattern matching and ADTs. My conclusion is that for a lot of tasks the benefit from Rust came from ML cicra 1990, not lifetimes etc. I feel…

> I feel if OCaml had got its act together around about 2010 with multicore and a few other annoyances[1] it could have been Rust

That's about the time-frame where I got into OCaml so I followed this up close.

The biggest hindrance in my opinion is/was boxed types.

Too much overhead for low level stuff, although there was a guy from oxbridge doing GL stuff with it.

Re: OCaml as my primary language

#142

As someone who uses OCaml for hobby projects, I appreciate how little the language gets in your way when you want to just “get shit done”, despite the language’s origins in academia and industrial uses. The type system usually means that I might take longer to get my code to compile, but that I won’t spend much (if any) time debugging it once I’m done. I’m in the middle of pulling together bits of a third party libra…

I almost never find a use for GADTs or functors or carefully specifying module types, but when I need them, they help me get stuff done neatly.

Even the object system which most OCaml developers avoid, is actually very useful for some specific modelling scenarios (usually hierarchies in GUIs or IaC) that comes with similar type system guarantees and minimal type annotations.

Re: OCaml as my primary language

#143
OCaml is probably my favourite language.

The most involved project I did with it was a CRUD app for organising Writer's Festivals.

The app was 100% OCaml (ReasonML so I could get JSX) + Dream + HTMX + DataTables. I used modules to get reusable front end templates. I loved being able to make a change to one of my data models and have the compiler tell me almost instantly where the change broke the front end. The main value of the app was getting data out of excel into a structured database, but I was also able to provide templated and branded itineraries in .odt format, create in memory zipped downloads so that I didn't need to touch the server disk. I was really impressed by how much I could achieve with the ecosystem.

But having to write all my database queries in strings and then marshal the data through types was tiring (and effectively not compile time type checked) and I had to roll my own auth. I often felt like I was having to work on things that were not core to the product I was trying to build.

I've spent a few years bouncing around different languages and I think my take away is that there is no perfect language. They all suck in their own special way.

Now I'm building an app just for me and I'm using Rails. Pretty much everything I've wanted to reach for has a good default answer. I really feel like I'm focused on what is relevant to the product I'm building and I'm thinking about things unrelated to language like design layout and actually shipping the thing.

Re: OCaml as my primary language

#144

Earlier quoted context omitted.

doesnt rust still have the advantage of having no gc? I dont like writing rust, but the selling point of being able to write performative code with memory safety guarantees has always stuck with me

I think "no gc but memory safe" is what originally got people excited about Rust. It's a genuinely new capability in production ready languages. However, I think Rust is used in many contexts where a GC is just fine and working with lifetimes makes many programs more painful to write. I think for many programs the approach taken by Oxidized OCaml[1] or Scala[2] gives 80% of the benefit while being a lot more ergonomi…

> So I think "no gc but memory safe" is what got people to look at Rust, but it's 1990s ML (ADTs, pattern matching, etc.) that keeps them there.

Yeah; this is my experience. I've been working in C professionally lately after writing rust fulltime for a few years. I don't really miss the borrow checker. But I really miss ADTs (eg Result, Option, etc), generic containers (Vec), tuples, match expressions and the tooling (Cargo).

You can work around a lot of these problems in C with grit and frustration, but rust just gives you good answers out of the box.

Re: OCaml as my primary language

#145

Question about terminology: Is it common to call higher-order function types "exponential types" as the article does? I know what higher-order functions are, but am having trouble grasping why the types would be called "exponential".

ackfoobar has already given a good reason why function types are called exponential, but there is an even deeper reason: function types interact algebraically the same way as exponents.

The type A → (B → C) is isomorphic to (A × B) → C (via currying). This is analogous to the rule (cᵇ)ᵃ = cᵇ˙ᵃ.

The type (A + B) → C is isomorphic to (A → C) × (B → C) (a function with a case expression can be replaced with a pair of functions). This is analogous to the rule cᵃ⁺ᵇ = cᵃ·cᵇ.

Re: OCaml as my primary language

#146
post #29

Earlier quoted context omitted.

That was my optimistic take before I started working on a large Haskell code base. Aside from the obvious problem that there's not enough FP in the training corpus, it seems like terser languages don't work all that well with LLMs. My guess is that verbosity actually helps the generation self-correct... if it predicts some "bad" tokens it can pivot more easily and still produce working code.

This has been my experience as well. Ai writes Go better than any language besides maybe html and JavaScript/python.

I wonder if it has more to do with larger training data than the languages themselves.

Re: OCaml as my primary language

#147
post #114

Earlier quoted context omitted.

I would say ReasonML also needed more follow-through. It seems like the OCaml community hasn't really rallied behind it.

It doesn't help that the OCaml community also has the problem that a significant minority seem to resent the fact that one company (Jane Street) has written more OCaml than the the rest of the world combined and then some and so de facto controls the ecosystem. Whereas the Go and Rust communities, for example, were just fine with having corporate sponsorship driving things.

Golang is interesting.. Hasn't steering loosened up a bit in recent years?

But going way back while yeah the team at Google controlled the direction, there were some pretty significant contributions from outside to channels, garbage collection, and goroutines and scheduling..

Re: OCaml as my primary language

#148

I saw a talk by someone from Google about their experiences using Rust in the Android team. Two points stuck out: they migrated many projects from Python, so performance can't have been that much of a concern, and in their surveys the features people liked most were basics like pattern matching and ADTs. My conclusion is that for a lot of tasks the benefit from Rust came from ML cicra 1990, not lifetimes etc. I feel…

> I feel if OCaml had got its act together around about 2010 with multicore and a few other annoyances[1] it could have been Rust.

No, that wouldn't have made the difference. No-one didn't pick up OCaml because it didn't have multicore or they were annoyed by the semicolons.

People don't switch languages because the new language is "old language but better". They switch languages because a) new language does some unique thing that the old language didn't do, even if the unique thing is useless and irrelevant, b) new language has a bigger number than old language on benchmarks, even if the benchmark is irrelevant to your use case, or c) new language claims to have great interop with old language, even if this is a lie.

There is no way OCaml could have succeeded in the pop culture that is programming language popularity. Yes, all of the actual reasons to use Rust apply just as much to OCaml and if our industry operated on technical merit we would have migrated to OCaml decades ago. But it doesn't so we didn't.

Re: OCaml as my primary language

#149
I’d have liked to see the use of dependency injection via the effects system expanded upon. The idea that the example program could use pattern matching to bind to either test values or production ones is interesting, but I can’t conceptualize what that would look like with the verbal description alone.

Also, I had no idea that the module system had its own type system, that’s wild.

Re: OCaml as my primary language

#150
post #55

I saw a talk by someone from Google about their experiences using Rust in the Android team. Two points stuck out: they migrated many projects from Python, so performance can't have been that much of a concern, and in their surveys the features people liked most were basics like pattern matching and ADTs. My conclusion is that for a lot of tasks the benefit from Rust came from ML cicra 1990, not lifetimes etc. I feel…

I'd say that Google strives to have a reasonably short list of languages approved for production-touching code. Rust can replace / complement C++, while OCaml cannot (it could replace Go instead... fat chance!). So I suspect that the team picked Rust because it was the only blessed language with ADTs, not because they won't like something with faster compile times. No way OCaml could have stolen the Rust's thunder: w…

In 2010, Ada 2005 was the most bare-metal-worthy expressive language. Now that would be Ada 2022.
Post reply on HN