Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The ocaml standard library is minimal to a fault. It's just enough to implement the compiler itself. For higher level operations like starts_with, you use libraries. The Batteries library for example provides what you want:

    String.starts_with line "+++"


Note, that the original code reads:

    when String.length line > 4 && String.sub line 0 3 = "+++"
And the Batteries library is not being used in the original code. If that doesn't tell you anything, I'm sorry. And good luck.


It's a problem. Until people have standardized on which 'better standard library' to use, programs will keep building from these too low level building blocks.


It is a style, not a problem. OCaml had been there a long long time. I've brushed with it a couple of times over the years, and every time the same thing.

You look at some random OCaml code, and it looks like this:

    when String.length line > 4 && String.sub line 0 3 = "+++"
I'm looking at it, and I'm not even sure - is it a bug there? Should it be '>=3' or they've really wanted to say '> 4'. Numbers all other the place? Ten different variants of equal signs?


You can call it a style if that makes a difference. I think there are reasons behind that style, and I think the too minimal standard library is the main reason. The lack of a good package manager until recently may be another contributing reason.

I hesitate to answer your hyperbole about ten variants of equal signs. It's not uncommon for languages to have two notions of equality like ocaml has (or even more): Here's Python for example: http://stackoverflow.com/questions/132988/is-there-a-differe...

To answer your original question of why anyone would prefer to not use startswith: I don't think anyone does.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: