this post was submitted on 14 Nov 2023
158 points (92.9% liked)

Programmer Humor

32480 readers
280 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 12 comments
sorted by: hot top controversial new old
[–] vox@sopuli.xyz 31 points 1 year ago (1 children)

rudt has implicit typing by default for variables tho...?

[–] FishFace@lemmy.world 8 points 1 year ago (2 children)

Yeah but it doesn't cross function boundaries so it's more limited.

[–] Knusper@feddit.de 22 points 1 year ago (1 children)

In other words, in OCaml, you don't have to write type annotations into the function parameter list. It will infer even those.

It's useful for small ad-hoc functions, but personally, I'm glad that Rust is more explicit here.

[–] vox@sopuli.xyz 6 points 1 year ago* (last edited 1 year ago)

yeah structs, consts ets should always be explicit, prevents a lot oh headache
also, for adhoc stuff rust has closures which can be fully inferred (but you need to convert them to explicit function pointers for storage in structs/consts)

[–] fl42v@lemmy.ml 5 points 1 year ago* (last edited 1 year ago) (1 children)

It's not like it's more limited, it's just so that it can yell at you when you return not what you said you're going to, IMO

[–] FishFace@lemmy.world 1 points 1 year ago

OCaml allows you to specify return types, but doesn't force you to.

[–] Prunebutt@feddit.de 13 points 1 year ago

Why am I laughing? I don't know any of these languages?

[–] meteokr@community.adiquaints.moe 9 points 1 year ago (2 children)

Feel like this joke would work better with TS | JS. Since that's the point of the former. I don't know how rust and ocaml are related?

[–] Knusper@feddit.de 14 points 1 year ago (1 children)

The initial creator of Rust, Graydon Hoare, took lots of inspiration from OCaml. In fact, the first Rust compiler was written in OCaml.

I appreciate that fun fact. The meme now makes more sense.

[–] charje@lemmy.ml 1 points 1 year ago

JS doesn't do any type inference. Ocaml Connor l type checker knows all the types and is completely type safe without type annotations.

[–] xmunk@sh.itjust.works 4 points 1 year ago

OCaml stronk... it's an amazing language that more people should be familiar with!