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

Missing from this post: string_of_int, int_of_string, +, +., etc. That alone is a massive turn-off for me, I'd rather write C at that point. Any modern language necessitates some kind of polymorphism and make user-defined types feel like first-class citizens.



> string_of_int, int_of_string

That didn't bother me so much because i speak spanish and can read french. OCaml is of french origin. `string_of_int` is a bad english translation—should have been `string_from_int`.

I like F# where I can use the `int` or `string` functions:

    let myString = "2024"
    let myInt = int myString
    let myStringAgain = string myInt


The Ocaml library added a Int module with a function to_string (so Int.to_string) and a generic printer ages ago. There is also a (+) operator for Float in the float module which you can open in any scope if you so wish.

Ocaml obviously supports polymorphism and an extremely expressive type system. The fact that operators are not polymorphic is purely a choice (and a good one).


As the other commenter mentioned, its a mistranslation. I read string_of_int as "string out of int" to make it better.


Interestingly enough, OCaml has a great polymorphism story in its OO system. Because it is structurally typed with nearly automatic inference, you can in fact write completely generic code like `x#y(z)`, which magically "just works" for any x that has a method y that accepts z - all inferred and statically type-checked.


> Because it is structurally typed with nearly automatic inference, you can in fact write completely generic code like `x#y(z)`, which magically "just works"

aka let's mix two jars of jam and shit via this funnel and see what happens.


On the contrary, static and structural typing are a match made in heaven.


Interesting. Why doesn't the standard lib use that for the examples I listed?


Because those types are not object types, so they don't have methods associated with them at all. This is unlike, say, CLR languages in which all types are object types.

There's been research on modular implicits for OCaml to solve this more generally, but that's not landing upstream anytime soon.




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: