Live data from Hacker News

OCaml as my primary language

xvw.lol

71–80 of 296 posts

Re: OCaml as my primary language

#71
I'm sure there's merit to the language, but the syntax seems absolutely alien to me. Some attempt to look like verbose imperative code, a bunch of semicolons, and for some strange reason, hate of parenthesis.

Real life sample:

    let print_expr exp =
        (* Local function definitions *)
        let open_paren prec op_prec =
          if prec > op_prec then print_string "(" in
        let close_paren prec op_prec =
          if prec > op_prec then print_string ")" in
        let rec print prec exp =     (* prec is the current precedence *)
          match exp with
            Const c -> print_float c
          | Var v -> print_string v
          | Sum(f, g) ->
              open_paren prec 0;
              print 0 f; print_string " + "; print 0 g;
              close_paren prec 0
          | Diff(f, g) ->
              open_paren prec 0;
              print 0 f; print_string " - "; print 1 g;
              close_paren prec 0
          | Prod(f, g) ->
              open_paren prec 2;
              print 2 f; print_string " * "; print 2 g;
              close_paren prec 2
          | Quot(f, g) ->
              open_paren prec 2;
              print 2 f; print_string " / "; print 3 g;
              close_paren prec 2
        in print 0 exp;;
A function is defined as:

    let print_expr exp =
That seems pretty hard to read at a glance, and easy to mistype as a definition.

Also, you need to end the declaration with `in`?

Then, semicolons...

    open_paren prec 0;
    print 0 f; print_string " + "; print 0 g;
... and even double semicolons ...

    print 0 exp;;
That looks like a language you really want an IDE helping you with.

Re: OCaml as my primary language

#72

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…

OCaml also needed the brief but bright ReasonML moment to add/fix/improve some of the syntax IIRC and work on user-friendly error messages. But this should've definitely happened much much earlier than it did.

Re: OCaml as my primary language

#73
post #6

I haven't worked in OCaml but I have worked a bit in F# and found it to be a pleasant experience. One thing I am wondering about in the age of LLMs is if we should all take a harder look at functional languages again. My thought is that if FP languages like OCaml / Haskell / etc. let us compress a lot of information into a small amount of text, then that's better for the context window. Possibly we might be able to p…

Procedures can be much more concise in functional/ML syntax, but many things are not -- dependency injection in languages like C# for example are able to be much less verbose because of really excellent DI libraries and (arguably more sane) instance constructor syntax.

Re: OCaml as my primary language

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

Re: OCaml as my primary language

#75

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…

> I think "no gc but memory safe" is what originally got people excited about Rust.

I think it was more about "the performance of C, but with memory safety and data race safety".

Re: OCaml as my primary language

#76
post #41

I wish somebody with this amount of experience would compare the benefits / shortcomings of using the ReasonML syntax. (The article mentions it once, in passing.)

I don't have extensive experience but the little I did was issues with LSP not working as well.

Re: OCaml as my primary language

#77

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

Usually we speaking only about sum and product (because article usually refers to ADT, so Algebraic Data type). A function is not really Data, so it is not included. But you can use the same tricks (ie: a -> b has arity b^a) to compute the number of potential inhabitant

Re: OCaml as my primary language

#78

What a brilliant article, it really puts to rest for me, the whole “why not use F#?” argument. In almost every OCaml thread, someone suggests F# as a way to sidestep OCaml’s tooling. I’ve always been curious about OCaml, especially since some people call it “Go with types” and I’m not a fan of writing Rust. But I’m still not sold on OCaml as a whole, its evangelists just don’t win me over the way the Erlang, Ruby, Ru…

It's been a few years since I've touched OCaml - the ecosystem just wasn't what I wanted - but the core language is still my favorite.

And the best way I can describe why is that my code generally ends up with a few heavy functions that do too much; I can fix it once I notice it, but that's the direction my code tends to go in.

In my OCaml code, I would look for the big function and... just not find it. No single workhorse that does a lot - for some reason it was just easier for me to write good code.

Now I do Rust for side projects because I like the type system - but I would prefer OCaml.

I keep meaning to checkout F# though for all of these reasons.

Re: OCaml as my primary language

#79

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…

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

Considering how many applications are running in JS/Python execution speed or GC is a low concern for many programs. Ergonomics (community, compiler guarantees, distribution, memory pressure, talent availability, whatever) seem more meaningful.

Re: OCaml as my primary language

#80

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…

There is absolutely no reason to use double semicolons in practice. The only place you really should see it is when using the repl.

Yeah, it makes me think he doesn't understand them in OCaml.
Post reply on HN