Live data from Hacker News

My thoughts on OCaml

osa1.net

141–150 of 230 posts

Re: My thoughts on OCaml

#142
post #21
post #3

Why would a company use ocaml? I’ve worked in software now for most of my life, from small to the biggest companies. I’ve watched teams with senior developers use non mainstream languages to build services and just about every time those devs get board again, leave the team, leaving them stuck with this system that’s hard to develop and different from the rest of the orgs, eventually resulting in a complete rewrite.…

A language like ocaml excels when the input and output are program-like, and the problem can't be number-crunched by hardware. The typical example would be a compiler. Other examples would be model checkers, code generators for number crunching libraries, proof assistants, and so on. Complex problems, where you need to explore different avenues of approach quickly, and where symbolic manipulation is at the heart of t…

The question is if modern versions of popular languages (java, c#) caught up on ocaml's syntax sugar, or maybe this syntax sugar is trivially replaceable by some utility functions.

Maybe you could bring any example of such ocaml functionality?

Re: My thoughts on OCaml

#143

Earlier quoted context omitted.

Because they are not issues on a day to day basis when you use the language. I used Ocaml for a paid internship some years ago. I was very much a beginner. Do you know how many time I felt at loss or annoyed by type conversion or the precedence rules for various part of the syntax? I never did. The truth is you never encounter the precedence rules when writing Ocaml normally using parentheses like a normal human bein…

> The issue is that this is not what’s going to annoy you as an Ocaml beginner. Sure, but tbf, the post is about what annoys the author, not what would annoy beginners. As you say, the author is not a beginner, and so their problems wouldn't be beginner problems.

That’s not the point I was making. They are not expert problems either. How often as an expert do you think you encounter precedence issues you were not encountering as a beginner?

Re: My thoughts on OCaml

#144

Related: https://twitter.com/zetalyrae/status/1639474931086901248 My OCaml: let foo (x: bar): baz = (\* Is this quuxable? *) match is_quuxable x with | Yes -> (* Then, we have to ... \*) All the OCaml I see in the wild: qlet%bind f = 's 't 'a 'b (fun ꙮ -> ꙮ ((

Hmm. I haven't seen the latter in OCaml as much. More the opposite; when I first used it, things like list length in the standard library weren't tail recursive. 8-|

Now, Haskell and shudder Scala shudder, on the other hand.

Re: My thoughts on OCaml

#145

Earlier quoted context omitted.

Ocaml has no ad-hoc polymorphism but you can use parametrised modules to write generic code which you will have to specialise at some point. That brings you ninety percents of the way in term of what ad-hoc polymorphism is used for. It's more cumbersome but I prefer it to the complexity involved by what Scala does for exemple.

Would you not consider the object system to be ad-hoc polymorphism?

It uses structural typing not ad-hoc polymorphism. Plus it’s rarely used and it used to give hard to parse error messages when you made type mistakes. I don’t really see it as an adequate replacement for ad-hoc polymorphism.

Re: My thoughts on OCaml

#146
post #134

Earlier quoted context omitted.

> What does that mean? That's a best practice. Like always using braces in C or Java or not using ternary operators in hard to read way. The syntax is unambiguous but non obvious to read if you don't know precedence rules as it is for most languages. You can make it explicit using parentheses which you should. I personally agree that parentheses around tuples should be mandatory but it's fairly easy to just put them.

Those are examples of C and Java being very bad . So yea, I think my point stands.

I’m not sure I understand your point then because the code in the article is definitely very bad OCaml which is what I have been trying to tell you from the start.

Re: My thoughts on OCaml

#147

Earlier quoted context omitted.

> You gave a beautiful answer about programming language You do the same thing as in Rust, Scala or Haskell and derive the printer [1]. Then at the callsite, if you know the type then you do `T.show` to print it or `T.eq`. If you don't know the type, then you pass it in at the top level as a module and then do `T.show` or `T.eq`. > Or to convert one type into another type? If you want to convert a type, then you have…

Okay...so you have to add a third party library to print? Yes, recursive data structures are a pain in Rust (well, recursive multi-owner data structures). But that's like comparing changing your oil to opening your car door. We do one of these a lot more. And bear in mind, I had to find this answer by googling and reading a random forum post. That's some pretty poor documentation. And that's not talking about aesthet…

People have to realize that printing is the least of your concern. Visible representation is not solving problem.

Re: My thoughts on OCaml

#148

> No standard and easy way of implementing interfaces. > In Haskell, this is done with typeclasses ... > In OCaml there’s no way to do this. I have to explicitly pass functions along with my values, maybe in a product type, or with a functor, or as an argument. Haskell is a mixed community / paradigm language too. I routinely program in "Braindead Haskell" (keep stuff simple and direct as much as possible). Funnily,…

> the Handle pattern

I love this so much.

Re: My thoughts on OCaml

#149
post #109

I think you should give F# a shot instead. 1. No standard and easy way of implementing interfaces No problem in F#, you have interfaces, abstract classed, ... 2. Bad standard library In F# you have access to the full .NET standard library and ecosystem. There are also quite a lot of libraries that are especially designed to take advantage of F# (SQL libs for example). 3. Syntax problems 3.1 OCaml doesn’t have a singl…

I really wish to like F# but the line noise kills me every time. I would kill for a "visual basic" f# where the absurd terseness is replaced with a little less noise. E.g. instead of seq use sequence, instead of abstract one letter symbols use words.

This is my exact issue with many "modern" languages. The code is not meant to be read later.

Re: My thoughts on OCaml

#150
An alternative to OCaml is Flix (https://flix.dev/) which attempts to address some of the critiques in the post. For example:

> Bad standard library

A particular goal of Flix is to have a consistent standard library based on type classes.

> Standard types are sometimes persistent, sometimes mutable. List, Map, and Set are persistent. Stack and Hashtbl are mutable.

In Flix immutable types are named List, Set, Map, etc. and mutable collections are prefixed with Mut, e.g. MutSet, MutMap, etc. Mutable data types also carry a region.

> Also, OCaml has no tracking of side-effects (like in Haskell)

Flix has an effect system that tracks purity/impurity.

(I am one of the developers of Flix)

Post reply on HN