10 ms·
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
by yazzku 2y ago
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.
- int_19h 2y agoInterestingly 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.
- yazzku 2y agoInteresting. Why doesn't the standard lib use that for the examples I listed?
- debugnik 2y agoBecause 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.
- instig007 2y ago> 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.
- int_19h 2y agoOn the contrary, static and structural typing are a match made in heaven.
- devmunchies 2y ago> 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
- RandomThoughts3 2y agoThe 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).
- jbhoot 2y agoAs the other commenter mentioned, its a mistranslation. I read string_of_int as "string out of int" to make it better.