Live data from Hacker News

OCaml as my primary language

xvw.lol

121–130 of 296 posts

Re: OCaml as my primary language

#121
I tried to like OCaml for a few years. The things that hold me back the most are niggling things that are largely solved in more "modern" langs, the biggest being the inability to "print" arbitrary objects.

There are ppx things that can automatically derive "to string" functions, but it's a bit of effort to set up, it's not as nice to use as what's available in Rust, and it can't handle things like Set and Map types without extra work, e.g. [1] (from 2021 so situation may have changed).

Compare to golang, where you can just use "%v" and related format strings to print nearly anything with zero effort.

[1] https://discuss.ocaml.org/t/ppx-deriving-implementation-for-...

Re: OCaml as my primary language

#122
post #45
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.

> terser languages don't work all that well with LLMs I’d believe that, but I haven’t tried enough yet. It seems to be doing quite well with jq. I wonder how its APL fares. When Claude generates Haskell code, I constantly want to reduce it. Doing that is a very mechanical process; I wonder if giving an agent a linter would give better results than overloading it all to the LLM.

Apl is executed right to left and LLMS.... Aren't.

Re: OCaml as my primary language

#123
Is OCaml somewhat suitable for desktop GUI app programming?

I saw this in the OP:

>For example, creating a binding with the Tk library

and had also been thinking about this separately a few days ago, hence the question.

Re: OCaml as my primary language

#124
post #23

I migrated from OCaml to Rust around 2020, haven't looked back. Although Rust is quite a lot less elegant and has some unpleasant deficiencies (lambdas, closures, currying)... and I end up having to close one one eye sometimes and clone some large data-structure to make my life easier... But regardless, its huge ecosystem and great tooling allows me to build things comparatively so easily, that OCaml has no chance. A…

Were you using the ocamlopt compiler? By default, ocaml runs in a VM, but few people figure that out because it is not screaming its name all the time like a pokemon (looking at you JVM/CLR). But ocaml can be compiled to machine code with significant performance improvements.

> By default, ocaml runs in a VM,

The Dune build system does default to ocamlopt nowadays, although maybe not back around 2020.

Re: OCaml as my primary language

#125

Earlier quoted context omitted.

> The moment you start ripping cases as distinct types out of the sum-type, you create the ability to side-step exhaustiveness and sum-types become useless in making invalid program states unrepresentable. Quite the opposite, that gives me the ability to explicitly express what kinds of values I might return. With your shape example, you cannot express in the type system "this function won't return a point". But with…

> With your shape example, you cannot express in the type system "this function won't return a point". Sure you can, that's just subtyping. If it returns a value that's not a point, the domain has changed from the shape type and you should probably indicate that. structure Shape = struct datatype shape = Circle of real | Rectangle of real * real | Point end structure Bound = struct datatype shape = Circle of real | R…

You wrote a lot of words to say very little.

Anyway, to translate your example:

    sealed interface Shape permits Point, Bound {}
    final class Point implements Shape {}
    sealed interface Bound extends Shape permits Circle, Rectangle {}
    record Circle(double radius) implements Bound {}
    record Rectangle(double width, double height) implements Bound {}
A `Rectangle` is both a `Bound` (weird name choice but whatever), and a `Shape`. Thanks to subtyping, no contortion needed. No need to use 7 more lines to create a separate, unrelated type.

> the Japanese word for "name" sounds like the English word, despite not being a loan word.

Great analogy, except for the fact that someone from the Java team explicitly said they're drawing inspirations from ML.

https://news.ycombinator.com/item?id=24203363

Re: OCaml as my primary language

#127

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".

I had the same doubt.

Here is my uneducated guess:

In math, after sum and product, comes exponent :)

So they may have used that third term in an analogous manner in the example.

Re: OCaml as my primary language

#128

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. Arguably, that could have been Scala and for a while it seemed like it would be Scala but then it kind of just... didn't. I suspect some of that was that the programming style of some high profile Scala packages really alienated people by pushing the type system and operator overloading m…

Scala was always going to be hamstrung by the fact that it's a JVM language and yes, the crazy stuff people did with the language didn't help.

Re: OCaml as my primary language

#129

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…

> aesthetically the double semicolons are an abomination and irk me far more. I think they have been optional for like 20 years, except in the top-level interactive environment to force execution. That being said, I still don't get why people are so much upset with the syntax. You'll integrate it after a week writing OCaml code.

I spent more than a week writing ocaml and still found the syntax pretty annoying. ReasonML would have been nice if the Ocaml community actually cared, but they are a bit insular.

Re: OCaml as my primary language

#130

Extremely dated. No HKTs, no typeclasses (modules are not a good substitute), no call-site expansion.

- Extremely dated: we have almost one new release every six month and in recent releases, the language runtime has been changed and user-defined effects have been introduced.

- No HKTs "in your sense" but: ```ocaml module type S = sig type 'a t end `` `type 'a t` is an Higher Kinded type (but in the module Level). - No typeclasses, yes, for the moment but the first step of https://arxiv.org/pdf/1512.01895 is under review: https://github.com/ocaml/ocaml/pull/13275 - no call-site expansion ? https://ocaml.org/manual/5.0/attributes.html look at the attribute `inline`.

Post reply on HN